44using System . Reflection ;
55using Autodesk . Revit . DB ;
66using RevitDBExplorer . Domain . DataModel . Accessors ;
7- using RevitDBExplorer . Domain . DataModel . Members . Accessors ;
87using RevitDBExplorer . Domain . DataModel . Members . Internals ;
98using 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 }
0 commit comments