lundi 22 avril 2019

Is there a way to get the PropertyInfo from a accessor?

Is there a way to retrieve the PropertyInfo of a property if you have its accessor(s), without going through every property and seeing if the accessors match?

e.g.

//This example uses a sample from a obfuscated assembly
public class ObjectInfo
{
    //the property which to get (laid out)
    public int UQIOWVICXJ
    {
        [CompilerGenerated]
        public int get_Id();

        [CompilerGenerated]
        private void HVKXLIREWQ(int num);
    }
}

//retrieve method
public static PropertyInfo GetIdProp()
{
   var get_accessor = typeof(ObjectInfo).GetMethod("get_Id", BindingFlags.Public | BindingFlags.Instance);

   return //the property info via get_accessor;
}

The only way I see of doing this is by calling typeof(ObjectInfo).GetProperties(//All Prop BindingFlags) and then, for each info in the result, check if the get method's name is equal to get_Id.





Aucun commentaire:

Enregistrer un commentaire