我有一个看起来像这样的 DTO:
public class MyDto
{
[MyAttribute("attribute1")]
public string Property1 {get;set;}
[MyAttribute("attribute2")]
public string Property2 {get;set;}
}
如果我有 string“attribute1”,我如何使用它来获取 MyDto 实例中 Property1 的值?
请您参考如下方法:
使用Reflection .遗憾的是,无法从属性中获取属性:您必须遍历每个属性并检查其属性。
