samedi 6 octobre 2018

Reflection, get key-value pair of generic dictionary

How can i get the Key for a specific MyData.Name value? I dont need to modify the Dictionary

public class MyBase
{
    protected struct MyData
        {
            public string Name;         
        }
}

public class MyClass : MyBase
{
    private readonly Dictionary<ulong,MyBase.MyData> m_Data = new Dictionary<ulong, MyBase.MyData>();
}

public class Test
{
    Type MyDataType = typeof(MyBase).GetNestedType("MyData", BindingFlags.Instance | BindingFlags.NonPublic);
    var m_Data = typeof(MyClass).GetField("m_Data", BindingFlags.Instance | BindingFlags.NonPublic);


    // How can i get the Key for a specific MyData.Name value?
}





Aucun commentaire:

Enregistrer un commentaire