指定属性继承规则

AttributeUsage的最后一个参数是继承标志,指出速航行是否可以被继承。如果设为true,它的意义取决于AllowMultiple属性的值。

继承

AllowMultiple

结果

True

False

派生的属性覆盖基属性

True

True

派生的属性和基属性共存


AttributeUsage属性 - 指定属性继承规则using System;
AttributeUsage属性 - 指定属性继承规则
using System.Reflection;
AttributeUsage属性 - 指定属性继承规则
AttributeUsage属性 - 指定属性继承规则
namespace AttribInheritance
                

当AllowMultiple被设置为false时,结果为:
Custom Attribute : def
当AllowMultiple被设置为true时,结果为:
Custom Attribute : def
Custom Attribute : abc
注意,如果将false传递给GetCustomAttributes,它不会搜索继承树,所以你只能得到派生的类属性。

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2021-05-31
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案