views:

156

answers:

2

Hi, I wanna get the value of a private member, so I wrote the following:

var f = e.
          GetType().
          GetFields(System.Reflection.BindingFlags.NonPublic |
                    System.Reflection.BindingFlags.Instance | 
                    System.Reflection.BindingFlags.DeclaredOnly)[0];
object o = f.FieldType.GetProperty("RowIndex").GetValue(f.FieldType, null);

but the method "GetValue" needs the original object in the first parameter, and I don't have this object, because I get in runtime. Could anyone help-me?!

+11  A: 

I think in your example the original object would be e would it not?

Kindness,

Dan

Daniel Elliott
A: 

You might have better luck if you actually separate out this reflected call into its component pieces. It looks to me like the original object is actually going to be the PropertyInfo generated by

f.FieldType.GetProperty("RowIndex")

I'd say if you actually declare a PropertyInfo object to hold this temporarily, you'd be able to pass it into the GetValue call and then destroy it when you're done.

Joel Etherton