Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Managed to make an improvement, mind, also found out that this test code suffers from infinite loops for self references (Array.Syncroot for example)</p> <p>In a nutshell it now finds things that inherit from IEnumerable (which is most indexed things) and use a foreach loop on those and coupled with the knowledge that the existing (ugly) code works for strings, it's now allot more thorough then it used to be...</p> <p>glad but disapointed that there doesn't seem to be a nice answer.</p> <p>Thanks for the help everyone</p> <hr> <p>Updated test code if someone finds themselves in a similar position</p> <pre><code> static void process( object obj ) { Type type = obj.GetType(); PropertyInfo[] properties = type.GetProperties(); // if this obj has sub properties, apply this process to those rather than this. if ( properties.Length &gt; 0 ) { foreach ( PropertyInfo prop in obj.GetType().GetProperties() ) { if ( prop.PropertyType.FindInterfaces( ( t, c ) =&gt; t == typeof( IEnumerable ), null ).Length &gt; 0 ) { MethodInfo accessor = prop.GetGetMethod(); MethodInfo[] accessors = prop.GetAccessors(); foreach ( object item in (IEnumerable)obj ) { process( item ); } } else if ( prop.GetIndexParameters().Length &gt; 0 ) { // get an integer count value, by incrementing a counter until the exception is thrown int count = 0; while ( true ) { try { prop.GetValue( obj, new object[] { count } ); count++; } catch ( TargetInvocationException ) { break; } } for ( int i = 0; i &lt; count; i++ ) { // process the items value process( prop.GetValue( obj, new object[] { i } ) ); } } else { // is normal type so. process( prop.GetValue( obj, null ) ); } } } else { // process to be applied to each property Console.WriteLine( "Property Value: {0}", obj.ToString() ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload