c# - 有没有办法从访问器获取 PropertyInfo?
问题描述
如果您有一个属性的访问器,有没有办法检索它们所附加到的 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
.
解决方案
推荐阅读
- image-processing - Photoshop Camera RAW/Lightroom 的色彩校准工具如何工作?
- php - 无法转换属性路径的值:预期的布尔值(用于复选框)
- java - Android 通知声音不是来自 /res
- c++ - C++ Qt,一个 SQL INSERT 查询耗时太长
- apache-spark - PySpark NaiveBayesModel.predict 错误
- aix - 修补 AIX 二进制文件
- python - 在不同的机器上恢复 TensorFlow 模型
- android - 如何在Android中解析xml文件中的属性/属性值
- ios - 如何安全地执行延迟选择器 iOS
- c# - 尽管使用了 SaveChanges(),但无法更改 EF 中的值