【发布时间】:2009-10-12 11:13:49
【问题描述】:
鉴于以下情况,如果设置为 AllowMultiple=false,我不希望编译器允许从基本属性派生的多个属性。事实上它编译没有问题 - 我在这里错过了什么?
using System;
[AttributeUsage(AttributeTargets.Property,AllowMultiple=false,Inherited=true)]
abstract class BaseAttribute : Attribute { }
sealed class DerivedAttributeA : BaseAttribute { }
sealed class DerivedAttributeB : BaseAttribute { }
class Sample1
{
[DerivedAttributeA()]
[DerivedAttributeB()]
public string PropertyA{ get; set; } // allowed, concrete classes differ
[DerivedAttributeA()]
[DerivedAttributeA()]
public string PropertyB { get; set; } // not allowed, concrete classes the same, honours AllowMultiple=false on BaseAttribute
}
【问题讨论】:
标签: c# inheritance attributes allowmultiple