dimanche 13 août 2023

Get static List<> field by Reflection

I have the following class:

    static class Sclass
    {
        internal static BitmapImage Img1 { get; private set; }
        internal static BitmapImage Img2 { get; private set; }
        internal static List<string> Names = new();
        internal static Dictionary<string, List<Creature>> Dict = new();
    }

I am trying to get all the above fields using reflection like so:

    var properties = typeof(Sclass).GetProperties(BindingFlags.NonPublic | BindingFlags.Static);

However, that only returns a collection of Img1 and Img2. I tried some different combinations of BindingFlags but I haven't been successful in getting neither Names nor Dict.

I read every reflection question I could find here but nothing worked.

How do I get a PropertyInfo[] collection of all 4 fields of my class Sclass?





Aucun commentaire:

Enregistrer un commentaire