Getting fields of a class through reflection
- by Water Cooler v2
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();
}