我正在尝试创建一个通用方法,该方法将读取类的属性并在运行时返回该值.我该怎么做?
注意:DomainName属性属于DomainNameAttribute类.
[DomainName("MyTable")]
Public class MyClass : DomainBase
{}
Run Code Online (Sandbox Code Playgroud)
我想要生成的内容:
//This should return "MyTable"
String DomainNameValue = GetDomainName<MyClass>();
Run Code Online (Sandbox Code Playgroud) 我需要能够从我的方法中读取我的属性的值,我该怎么做?
[MyAttribute("Hello World")]
public void MyMethod()
{
// Need to read the MyAttribute attribute and get its value
}
Run Code Online (Sandbox Code Playgroud)