vendredi 29 septembre 2017

Reflection. Generic Type field of anonymously elements

There is the code:

class Program {
        class Foo { public List<int> List = new List<int>();}

        static void Main()
        {
            Foo foo = new Foo();
            foo.List.Add(3);
            foo.List.Add(2);
            foo.List.Add(1);
            FieldInfo[] fInfo = foo.GetType().GetFields();
            object o = fInfo[0].GetValue(foo);
            foreach (object element in (???) o)
                        { ..... }
        }
}

My question is.. I received only o, and I know it parent object foo Pls, tell me how to iterate each element of o if I don't know what Types are in the Generic List<>? What kind of object is that? How to manage it?





Aucun commentaire:

Enregistrer un commentaire