Skip to content

Commit cedfe4b

Browse files
committed
refactor: finish move of MemberAccessors to a new home
1 parent 4d09c1a commit cedfe4b

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/MemberAccessorByIteration.cs renamed to sources/RevitDBExplorer/Domain/DataModel/Members/Accessors/MemberAccessorByIteration.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
using System.Reflection;
55
using Autodesk.Revit.DB;
66
using RevitDBExplorer.Domain.DataModel.Accessors;
7-
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
87
using RevitDBExplorer.Domain.DataModel.Members.Internals;
98
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
109

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

13-
namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
12+
namespace RevitDBExplorer.Domain.DataModel.Members.Accessors
1413
{
1514
internal sealed class MemberAccessorByIteration<TSnoopedObjectType, TReturnType> : MemberAccessorTypedWithDefaultPresenter<TSnoopedObjectType>
1615
{
1716
private readonly string getMethodReturnTypeName;
1817
private readonly ParameterInfo getMethodParameter;
1918
private readonly Func<TSnoopedObjectType, object, TReturnType> func;
20-
19+
2120

2221
public MemberAccessorByIteration(MethodInfo getMethod)
2322
{
@@ -32,38 +31,55 @@ public MemberAccessorByIteration(MethodInfo getMethod)
3231
protected override ReadResult Read(SnoopableContext context, TSnoopedObjectType @object)
3332
{
3433
var count = CountValues(context, getMethodParameter.ParameterType);
35-
return new ReadResult(Labeler.GetLabelForCollection(getMethodReturnTypeName, count), "[ByIteration]", true, false);
34+
var canBeSnooped = count > 0 || count.HasValue == false;
35+
return new ReadResult(Labeler.GetLabelForCollection(getMethodReturnTypeName, count), "[ByIteration]", canBeSnooped, false);
3636
}
3737
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, TSnoopedObjectType @object, IValueContainer state)
38-
{
39-
var result = new List<SnoopableObject>();
38+
{
39+
var result = new List<SnoopableObject>();
4040

4141
foreach (var input in StreamValues(context, getMethodParameter.ParameterType))
42-
{
42+
{
4343
object resultOfInvocation = null;
4444
try
4545
{
46-
resultOfInvocation = func(@object, input);
46+
resultOfInvocation = func(@object, input);
4747
}
4848
catch (Exception ex)
4949
{
50-
if (getMethodParameter.ParameterType == typeof(int))
50+
if (getMethodParameter.ParameterType == typeof(int) && IsNotExpectedException(ex))
5151
{
5252
break;
5353
}
54-
resultOfInvocation = Labeler.GetLabelForException(ex);
54+
resultOfInvocation = ex;// Labeler.GetLabelForException(ex);
5555
}
5656
result.Add(SnoopableObject.CreateInOutPair(context.Document, input, resultOfInvocation, keyPrefix: getMethodParameter.Name + ":"));
5757
}
5858

5959
return result;
6060
}
61+
private bool IsNotExpectedException(Exception ex)
62+
{
63+
if (ex is Autodesk.Revit.Exceptions.ArgumentOutOfRangeException)
64+
{
65+
return true;
66+
}
67+
68+
if (ex is Autodesk.Revit.Exceptions.ArgumentException argumentException)
69+
{
70+
if (argumentException.ParamName == "barEnd")
71+
{
72+
return false;
73+
}
74+
}
75+
return true;
76+
}
6177

6278
private IEnumerable<object> StreamValues(SnoopableContext context, Type type)
6379
{
6480
if (type == typeof(int))
6581
{
66-
for (int i = 0; i < 757; ++i)
82+
for (int i = 0; i < 757; ++i)
6783
{
6884
yield return i;
6985
}
@@ -76,7 +92,7 @@ private IEnumerable<object> StreamValues(SnoopableContext context, Type type)
7692
}
7793
}
7894
if (type == typeof(bool))
79-
{
95+
{
8096
yield return true;
8197
yield return false;
8298
}

sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/MemberAccessorByRef.cs renamed to sources/RevitDBExplorer/Domain/DataModel/Members/Accessors/MemberAccessorByRef.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
using System.Reflection;
44
using Autodesk.Revit.DB;
55
using RevitDBExplorer.Domain.DataModel.Accessors;
6-
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
76
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
87
using RevitDBExplorer.Domain.RevitDatabaseScripting;
98

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

12-
namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
11+
namespace RevitDBExplorer.Domain.DataModel.Members.Accessors
1312
{
1413
internal sealed class MemberAccessorByRef : MemberAccessorTypedWithDefaultPresenter<object>, IAccessorWithCodeGeneration
1514
{
16-
private readonly MethodInfo getMethod;
15+
private readonly MethodInfo getMethod;
16+
private readonly ParameterInfo[] parameters;
1717

1818

1919
public MemberAccessorByRef(MethodInfo getMethod)
20-
{
21-
this.getMethod = getMethod;
20+
{
21+
this.getMethod = getMethod;
22+
parameters = getMethod.GetParameters();
2223
}
2324

2425

2526
protected override ReadResult Read(SnoopableContext context, object @object)
2627
{
2728
var value = ValueContainerFactory.Create(getMethod.ReturnType);
28-
var paramsDef = getMethod.GetParameters();
29-
var resolvedArgs = ResolveArguments(paramsDef, context.Document, @object);
29+
var resolvedArgs = ResolveArguments(parameters, context.Document, @object);
3030
var result = getMethod.Invoke(@object, resolvedArgs);
3131
value.SetValue(context, result);
3232
return new ReadResult(value.ValueAsString, "[ByRef] " + value.TypeHandlerName, value.CanBeSnooped, value.CanBeVisualized, value);
3333
}
34-
34+
3535

3636
public static Type[] HandledParameterTypes = new[] { typeof(Document), typeof(Options), typeof(View), typeof(SpatialElementBoundaryOptions) };
3737

@@ -71,7 +71,7 @@ private object[] ResolveArguments(ParameterInfo[] paramsDef, Document doc, objec
7171
StoreFreeBoundaryFaces = true,
7272
SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center
7373
};
74-
}
74+
}
7575

7676
args[i] = argument;
7777
}

sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/MemberAccessorForConstValue.cs renamed to sources/RevitDBExplorer/Domain/DataModel/Members/Accessors/MemberAccessorForConstValue.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using RevitDBExplorer.Domain.DataModel.Accessors;
4-
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
54
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
65

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

9-
namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
8+
namespace RevitDBExplorer.Domain.DataModel.Members.Accessors
109
{
1110
internal sealed class MemberAccessorForConstValue : MemberAccessorTypedWithDefaultPresenter<object>
1211
{
13-
private readonly IValueContainer value;
12+
private readonly IValueContainer value;
1413

1514

1615
public MemberAccessorForConstValue(Type type, SnoopableContext context, object value)
@@ -21,7 +20,7 @@ public MemberAccessorForConstValue(Type type, SnoopableContext context, object v
2120

2221

2322
protected override ReadResult Read(SnoopableContext context, object @object)
24-
{
23+
{
2524
return new ReadResult(value.ValueAsString, value.TypeHandlerName, value.CanBeSnooped, value.CanBeVisualized, value);
2625
}
2726
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, object @object, IValueContainer state)

sources/RevitDBExplorer/Domain/DataModel/Members/MemberAccessorFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq.Expressions;
55
using System.Reflection;
66
using RevitDBExplorer.Domain.DataModel.Accessors;
7-
using RevitDBExplorer.Domain.DataModel.MemberAccessors;
87
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
98
using RevitDBExplorer.Domain.DataModel.Members.Internals;
109

sources/RevitDBExplorer/Domain/DataModel/Members/MemberStreamerForSystemType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using RevitDBExplorer.Domain.DataModel.MemberAccessors;
5+
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
56
using RevitDBExplorer.Domain.DataModel.Members.Base;
67

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

0 commit comments

Comments
 (0)