[英]Can you add a constraint that the Attribute can only be added to a property with public getter and setter in C#
在C#中,您可以使用AttributeTargetAttribute
来限制属性的范围。 在编译时检查此约束。
如果目标是AttributeTargets.Property
,是否有一种方法可以强制getter和setter都必须是公共的?
不在编译时。 如果通过在属性中进行反射来完成此操作,则可以在运行时强制实施它。 我的问题是:为什么要强制执行此操作?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.