다음은 컴파일러에서 AllowMultiple = false로 설정된 기본 특성에서 파생 된 여러 특성을 허용하지 않을 것이라고 가정합니다. 실제로 문제없이 컴파일됩니다. 여기서 무엇을 놓치고 있습니까?파생 된 특성 형식에 대한 AttributeUsage 적용
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
}
나는 그것이 사실일지도 모른다는 것을 두려워했다, 확인을위한 감사. –