C# - Silverlight - CustomAttribute with Enum
Posted
by cmaduro
on Stack Overflow
See other posts from Stack Overflow
or by cmaduro
Published on 2010-05-20T17:40:39Z
Indexed on
2010/05/21
13:00 UTC
Read the original article
Hit count: 531
I have the following class:
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class ModuleActivationButtonAttribute : ExportAttribute
{
public Enum TargetRegion { get; set; }
public ModuleActivationButtonAttribute(Enum targetRegion) : base(typeof(IModuleActivationButton))
{
TargetRegion = targetRegion;
}
}
The class compiles fine, but when I decorate my property with it:
[ModuleActivationButton(Regions.Tabs)]
public IModuleActivationButton ModuleActivationButton
{
get { return new ModuleActivationButton() as IModuleActivationButton; }
set { ModuleActivationButton = value; }
}
public enum Regions
{
Content,
Tabs
}
The compiler spits out:
Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type C:\...\Manpower4U.Modules.Home\HomeModule.cs 28 33 Manpower4U.Modules.Home
© Stack Overflow or respective owner