Can an attribute be set only in the Setter of an automatically implemented property?

I currently have this:

[SomeCustomAttribute] public string Name { get; set; } 

However, I want this attribute to decorate only the installer, not the recipient. Is there any way to do this?

+6
source share
2 answers

The following are syntactically allowed:

  public string Name { get; [SomeCustomAttribute] set; } 

The rest matches (your?) SomeCustom .

Of course, it should be a method attribute, not a property attribute.

+10
source
 public string Name { get; [SomeCustomAttribute] set; } 
+1
source

Source: https://habr.com/ru/post/911506/


All Articles