How to get name of property which our attribute is set?

后端 未结 3 653
小鲜肉
小鲜肉 2020-12-15 03:34

I\'m going to do this without passing any parameter to attribute! Is it possible?

class MyAtt : Attribute {
    string NameOfSettedProperty() {
        //How         


        
3条回答
  •  不思量自难忘°
    2020-12-15 03:53

    Using CallerMemberNameAttribute from .NET 4.5:

    public CustomAttribute([CallerMemberName] string propertyName = null)
    {
        // ...
    }
    

提交回复
热议问题