Can you add a constraint that the Attribute can only be added to a property with public getter and setter in C#

StackOverflow https://stackoverflow.com/questions/22367299

문제

In C#, you can limit the scope of an attribute with the AttributeTargetAttribute. This constraint is checked at compile time.

Is there a way to force that if the target is a AttributeTargets.Property, that both the getter and setter must be public?

도움이 되었습니까?

해결책

Not at compile-time. If you did this via reflection in the attribute, then you could enforce it at runtime. My question is: why do you want to enforce this?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top