有没有办法从访问器获取PropertyInfo?

时间:2019-04-23 02:56:41

标签: c# reflection

如果您有一个属性的访问器,是否有一种方法可以检索它们所附加的PropertyInfo,而无需遍历每个属性并查看访问器是否匹配?

例如

//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;
}

我看到的唯一方法是调用typeof(ObjectInfo).GetProperties(//All Prop BindingFlags),然后针对结果中的每个信息,检查get方法的名称是否等于get_Id

0 个答案:

没有答案
相关问题