我将在不向属性传递任何参数的情况下执行此操作!可能吗?
class MyAtt : Attribute {
string NameOfSettedProperty() {
//How do this? (Would be MyProp for example)
}
}
class MyCls {
[MyAtt]
int MyProp { get { return 10; } }
}
最佳答案
使用 CallerMemberNameAttribute来自 .NET 4.5:
public CustomAttribute([CallerMemberName] string propertyName = null)
{
// ...
}
关于c# - 如何获取我们的属性设置的属性名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4606973/