so I recently found out about reflection in c# and I got a problem. So I have a class that holds classes as fields (all of these fields have a method reset()
), and I tried getting all the fields names and then get their type and invoke their reset()
method like this:
List<string> fieldnames = new List<string>();
Type t = typeof(AnimationHolder);
foreach(MemberInfo m in t.GetFields())
{
fieldnames.Add(m.Name);
}
for (int i = 0; i < fieldnames.Count; i++)
{
Type atype = Type.GetType(fieldnames[i]);
MethodInfo reset = atype.GetMethod("Reset");
reset.Invoke(type.GetField(fieldnames[i]), null);
}
this just throws a NullReferenceException
, well I wasn't expecting much, but I'm really eager for the answer. Please help.