vendredi 1 janvier 2016

Reflection on static members of a generic type

I have the following class.

class MyClass<T>
{
    private static List<T> _Values;
    public static List<T> Values
    {
        get { return (_Values = _Values ?? new List<T>()); }
    }
}

I have used it several times like this.

MyClass<Int32>.Values.Add(1);
MyClass<String>.Values.Add("1");

Is there any possibility to retrieve all Lists of all types that have ever been used and are in the memory now using reflection?

Something like

var lists = typeof(MyClass<>)
    .MemoryOccurrences()
    .Select(x => x.GetStaticVariable("Values")); // two lists expected in this case





Aucun commentaire:

Enregistrer un commentaire