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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.