Page 1 of 1

[C#] Fieldinfo[]'s with Generic classes

Posted: Tue Apr 29, 2008 2:42 pm
by grimdoomer
Well, I set up a class for my reflexives like so:

Code: Select all

public class Reflexive<T> : List<T> where T : Chunk
    {

}
And I harcoded my Tags like engineer. But when I get a Reflexive<Chunk> field type, and I try to do:

Code: Select all

foreach (FieldInfo f  in Tag.Fields)
{
     //Blah Blah Blah
     else if (f.FieldType.IsGenericType &&   f.FieldType.GetGenericTypeDefinition() == typeof(Reflexive<>))
     {
            //-----------More stuff not important

            //Right here, I get an array with 0 Entrys
            FieldInfo[] FFields = f.GetType().GetFields();
     }
}
I get an array with 0 entrys for the line with the comment.

Can any one help me with this?

Posted: Tue Apr 29, 2008 3:57 pm
by xzodia
you need to specify the bindingflags
GetFields(BindingFlags.Public | BindingFlags.Instance)

Posted: Tue Apr 29, 2008 4:04 pm
by grimdoomer
I did but I still get an empty array.

I need to get the Fields of T, but I dont know how.

Posted: Tue Apr 29, 2008 4:41 pm
by xzodia
are you sure its the fields you want and not the members?

Posted: Tue Apr 29, 2008 5:07 pm
by grimdoomer
Yea, I need the fields so I can check for any nested TagReferences and add them to the TagReference list.