c# - ReadOnlyAttribute 与 PropertyDescriptor.IsReadOnly()

标签 c# attributes readonly propertydescriptor

使用为 IsReadOnly() 方法返回值的 PropertyDescriptor 和与 ReadOnlyAttribute 关联的有什么区别>?

最佳答案

主要区别在于,如果您提供自己的 PropertyDescriptor 实现(通过 ICustomTypeDescriptorTypeDescriptionProvider类型转换器)。然后您可以选择您的自己的逻辑何时可写 - 例如,基于访问权限。

但是是的;在默认实现下,对于没有 setter 的属性和标记有 ReadOnlyAttribute 的属性,它将报告只读。

关于c# - ReadOnlyAttribute 与 PropertyDescriptor.IsReadOnly(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/757289/

相关文章:

c# - SQL表变更分布

c# - Firebase 3 : creating a custom authentication token using . 网络和 c#

php - Prestashop 属性变更 - 相关属性显示

emacs - 交互调用 : Text is read-only: "Type ` e' to edit property"

c# - 为什么 'readonly' 在下面的 Singleton 实现中必不可少?

javascript - 当我将它添加到原始 html 时,html 属性 'readonly' 停止文本输入,但如果我通过 javascript 添加它则不会

c# - 从 html 字符串中获取 html 输入控件及其值

c# - 表中的枚举类值

javascript - 如何获取网站的所有src和href属性

python - python如何将属性写入对应的标签? (文中的详细示例可能有助于更好地理解它。)