views:

13

answers:

1

I've done it a gazillion times in the past and successfully so. This time, I'm suffering from lapses of amnesia.

So, I am just trying to get the fields on an object. It is an embarrassingly simple and stupid piece of code that I am writing in a test solution before I do something really useful in production code.

Strangely, the GetFieldsOf method reports a zero length array on the "Amazing" class. Help.

class Amazing
{
    private NameValueCollection _nvc;
    protected NameValueCollection _myDict;
}


private static FieldInfo[] GetFieldsOf(string className, 
        string nameSpace = "SomeReflection")
    {
        Type t;

        return (t = Assembly.GetExecutingAssembly().GetType(
             string.Format("{0}.{1}", nameSpace, className)
             )) == null ? null : t.GetFields();
    }
+2  A: 

Have a look at BindingFlags.
Try to set at least BindingFlags.Instance | BindingFlags.NonPublic in your GetFields() call.

tanascius
Cheers. You're the man!
Water Cooler v2