Skip to content

Commit

Permalink
refactor: more more compact syntax for MembersTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed May 14, 2024
1 parent 6e26331 commit 496fa08
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ internal class MemberOverride<TForType> : IMemberOverride
public static IMemberOverride ByFunc<TReturnType>(Expression<Func<Document, TForType, TReturnType>> getter)
{
var compiledGetter = getter.Compile();
var methodCallExpression = getter.Body as MethodCallExpression;
//var syntax = methodCallExpression.ToString();
var uniqueId = getter.GetUniqueId();

return new MemberOverride<TForType>()
{
UniqueId = uniqueId,
MemberAccessorFactory = () => new MemberAccessorByFunc<TForType, TReturnType>(compiledGetter)
MemberAccessorFactory = () =>
{
var accessor = new MemberAccessorByFunc<TForType, TReturnType>(compiledGetter);
//accessor.DefaultInvocation.Syntax = syntax;
return accessor;
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class RebarBarType_GetAutoCalcHookLengths : MemberAccessorByType<RebarB
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, RebarBarType rebarBarType)
{
var hookTypes = new FilteredElementCollector(context.Document).OfClass(typeof(RebarHookType));
foreach(var hookType in hookTypes)
foreach (var hookType in hookTypes)
{
yield return SnoopableObject.CreateInOutPair(context.Document, hookType, rebarBarType.GetAutoCalcHookLengths(hookType.Id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class RebarBarType_GetHookLength : MemberAccessorByType<RebarBarType>,
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, RebarBarType rebarBarType)
{
var hookTypes = new FilteredElementCollector(context.Document).OfClass(typeof(RebarHookType));
foreach(var hookType in hookTypes)
foreach (var hookType in hookTypes)
{
yield return SnoopableObject.CreateInOutPair(context.Document, hookType, rebarBarType.GetHookLength(hookType.Id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context,
{
var hookTypes = new FilteredElementCollector(context.Document).OfClass(typeof(RebarHookType));
var result = new List<SnoopableObject>();
foreach(var hookType in hookTypes)
foreach (var hookType in hookTypes)
{
try
{
result.Add(SnoopableObject.CreateInOutPair(context.Document, hookType, rebarBarType.GetHookOffsetLength(hookType.Id)));
}
catch(Exception ex)
catch (Exception ex)
{
result.Add(SnoopableObject.CreateInOutPair(context.Document, hookType, ex));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class RebarBarType_GetHookPermission : MemberAccessorByType<RebarBarTyp
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, RebarBarType rebarBarType)
{
var hookTypes = new FilteredElementCollector(context.Document).OfClass(typeof(RebarHookType));
foreach(var hookType in hookTypes)
foreach (var hookType in hookTypes)
{
yield return SnoopableObject.CreateInOutPair(context.Document, hookType, rebarBarType.GetHookPermission(hookType.Id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class RebarBarType_GetHookTangentLength : MemberAccessorByType<RebarBar
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, RebarBarType rebarBarType)
{
var hookTypes = new FilteredElementCollector(context.Document).OfClass(typeof(RebarHookType));
foreach(var hookType in hookTypes)
foreach (var hookType in hookTypes)
{
yield return SnoopableObject.CreateInOutPair(context.Document, hookType, rebarBarType.GetHookTangentLength(hookType.Id));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
Expand All @@ -10,36 +9,24 @@
namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class Document_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();

static Document_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
MemberTemplate<Document>.Create((doc, target) => Document.GetDocumentVersion(target), kind: MemberKind.StaticMethod),
{
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<Document>.Create((doc, target) => Document.GetDocumentVersion(target), kind: MemberKind.StaticMethod),
#if R2023_MIN
MemberTemplate<Document>.Create((doc, target) => target.GetChangedElements(Guid.Empty), kind: MemberKind.Method),
MemberTemplate<Document>.Create((doc, target) => target.GetChangedElements(Guid.Empty), kind: MemberKind.Method),
#endif

MemberTemplate<Document>.Create((doc, target) => BasicFileInfo.Extract(target.PathName), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => BasicFileInfo.Extract(target.PathName), kind: MemberKind.StaticMethod),

MemberTemplate<Document>.Create((doc, target) => BasePoint.GetSurveyPoint(doc), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => BasePoint.GetProjectBasePoint(doc), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => InternalOrigin.Get(doc), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => BasePoint.GetSurveyPoint(doc), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => BasePoint.GetProjectBasePoint(doc), kind: MemberKind.StaticMethod),
MemberTemplate<Document>.Create((doc, target) => InternalOrigin.Get(doc), kind: MemberKind.StaticMethod),

#if R2024_MIN
MemberTemplate<Document>.Create((doc, target) => doc.GetUnusedElements(new HashSet<ElementId>()), kind: MemberKind.Method),
MemberTemplate<Document>.Create((doc, target) => doc.GetAllUnusedElements(new HashSet<ElementId>()), kind: MemberKind.Method),
MemberTemplate<Document>.Create((doc, target) => doc.GetUnusedElements(new HashSet<ElementId>()), kind: MemberKind.Method),
MemberTemplate<Document>.Create((doc, target) => doc.GetAllUnusedElements(new HashSet<ElementId>()), kind: MemberKind.Method),
#endif

};
}


public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Structure.StructuralSections;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class Element_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();

static Element_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
MemberTemplate<Element>.Create((doc, target) => doc.ActiveView.GetElementOverrides(target.Id), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create((doc, target) => doc.GetWorksetId(target.Id), kind: MemberKind.AsArgument),
MemberTemplate<FamilyInstance>.Create((doc, target) => StructuralSectionUtils.GetStructuralSection(doc, target.Id), kind: MemberKind.StaticMethod),
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<Element>.Create((doc, target) => doc.ActiveView.GetElementOverrides(target.Id), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create((doc, target) => doc.GetWorksetId(target.Id), kind: MemberKind.AsArgument),
MemberTemplate<FamilyInstance>.Create((doc, target) => StructuralSectionUtils.GetStructuralSection(doc, target.Id), kind: MemberKind.StaticMethod),

MemberTemplate<Reference>.Create((doc, target) => doc.GetElement(target.ElementId).GetGeometryObjectFromReference(target), canBeUsed: x => x.ElementId != null, kind: MemberKind.AsArgument),
MemberTemplate<Reference>.Create((doc, target) => doc.GetElement(target.ElementId).GetGeometryObjectFromReference(target), canBeUsed: x => x.ElementId != null, kind: MemberKind.AsArgument),

#if R2023_MIN
MemberTemplate<Element>.Create((doc, target) => AnalyticalNodeData.GetAnalyticalNodeData(target), kind: MemberKind.StaticMethod, canBeUsed: x => x is ReferencePoint),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.HasAssociation), new AnalyticalToPhysicalAssociationManager_HasAssociation(), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementId), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementId(), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create((doc, target) => AnalyticalNodeData.GetAnalyticalNodeData(target), kind: MemberKind.StaticMethod, canBeUsed: x => x is ReferencePoint),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.HasAssociation), new AnalyticalToPhysicalAssociationManager_HasAssociation(), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementId), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementId(), kind: MemberKind.AsArgument),
#endif
#if R2024_MIN
MemberTemplate<Element>.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsAnalyticalElement(doc, target.Id), kind: MemberKind.StaticMethod),
MemberTemplate<Element>.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsPhysicalElement(doc, target.Id), kind: MemberKind.StaticMethod),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementIds), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementIds(), kind: MemberKind.AsArgument),
MemberTemplate<Element>.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsAnalyticalElement(doc, target.Id), kind: MemberKind.StaticMethod),
MemberTemplate<Element>.Create((doc, target) => AnalyticalToPhysicalAssociationManager.IsPhysicalElement(doc, target.Id), kind: MemberKind.StaticMethod),
MemberTemplate<Element>.Create(typeof(AnalyticalToPhysicalAssociationManager), nameof(AnalyticalToPhysicalAssociationManager.GetAssociatedElementIds), new AnalyticalToPhysicalAssociationManager_GetAssociatedElementIds(), kind: MemberKind.AsArgument),
#endif

};
}


public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
Expand All @@ -10,19 +9,9 @@ namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class FamilyInstance_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();

static FamilyInstance_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
MemberTemplate<FamilyInstance>.Create((doc, target) => AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(target), canBeUsed: (x)=> AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(x) , kind: MemberKind.StaticMethod),
};
}

public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<FamilyInstance>.Create((doc, target) => AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(target), canBeUsed: (x)=> AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(x) , kind: MemberKind.StaticMethod),
];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
Expand All @@ -10,23 +9,11 @@ namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class Family_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();


static Family_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
MemberTemplate<Family>.Create((doc, target) => doc.EditFamily(target), kind: MemberKind.AsArgument),
MemberTemplate<Family>.Create((doc, target) => FamilySizeTableManager.GetFamilySizeTableManager(doc, target.Id), kind: MemberKind.StaticMethod),
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<Family>.Create((doc, target) => doc.EditFamily(target), kind: MemberKind.AsArgument),
MemberTemplate<Family>.Create((doc, target) => FamilySizeTableManager.GetFamilySizeTableManager(doc, target.Id), kind: MemberKind.StaticMethod),

};
}


public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
];
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Base;
using RevitDBExplorer.Domain.DataModel.MembersTemplates.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class HostObject_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();


static HostObject_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<HostObject>.Create((doc, target) => HostObjectUtils.GetTopFaces(target), kind: MemberKind.StaticMethod),
MemberTemplate<HostObject>.Create((doc, target) => HostObjectUtils.GetBottomFaces(target), kind: MemberKind.StaticMethod),
MemberTemplate<HostObject>.Create(typeof(HostObjectUtils), "GetSideFaces", new HostObjectUtils_GetSideFaces(), kind: MemberKind.StaticMethod ),
};
}


public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.UI;
using Autodesk.RevitAddIns;
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
using RevitDBExplorer.Domain.DataModel.Members;
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
using RevitDBExplorer.Domain.DataModel.Members.Base;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
Expand All @@ -12,21 +11,9 @@ namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
{
internal class IExternalApplication_Templates : IHaveMemberTemplates
{
private static readonly IEnumerable<ISnoopableMemberTemplate> templates = Enumerable.Empty<ISnoopableMemberTemplate>();


static IExternalApplication_Templates()
{
templates = new ISnoopableMemberTemplate[]
{
MemberTemplate<IExternalApplication>.Create(typeof(AddInManifestUtility), "GetRevitAddInManifest", new MemberAccessorByFunc<IExternalApplication, RevitAddInManifest>((doc, target) => AddInManifestWizard.Get(target.GetType().Assembly.Location))),
};
}


public IEnumerable<ISnoopableMemberTemplate> GetTemplates()
{
return templates;
}
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
[
MemberTemplate<IExternalApplication>.Create(typeof(AddInManifestUtility), "GetRevitAddInManifest", new MemberAccessorByFunc<IExternalApplication, RevitAddInManifest>((doc, target) => AddInManifestWizard.Get(target.GetType().Assembly.Location))),
];
}
}
}
Loading

0 comments on commit 496fa08

Please sign in to comment.