簡體   English   中英

您是否可以添加一個約束,即只能使用C#中的public getter和setter將屬性添加到屬性?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM