我有以下课程:
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class ModuleActivationButtonAttribute : ExportAttribute
{
public Enum TargetRegion { get; set; }
public ModuleActivationButtonAttribute(Enum targetRegion) : base(typeof(IModuleActivationButton))
{
TargetRegion = targetRegion;
}
}
该类编译得很好,但是当我用它装饰我的财产时:
[ModuleActivationButton(Regions.Tabs)]
public IModuleActivationButton ModuleActivationButton
{
get { return new ModuleActivationButton() as IModuleActivationButton; }
set { ModuleActivationButton = value; }
}
public enum Regions
{
Content,
Tabs
}
编译器吐出:
Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type C:\...\CompanyX.Modules.Home\HomeModule.cs 28 33 CompanyX.Modules.Home