CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

MEF metadata view on custom export attribute

749 Views
Copy Code Show/Hide Line Numbers
public interface IRuleMetadata
{
    [DefaultValue(0)]
    int ExecutionOrder { get; }
}
 
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class RuleAttribute : ExportAttribute, IRuleMetadata
{
    public RuleAttribute(int executionOrder)
        : base(typeof(IRule))
    {
        this.ExecutionOrder = executionOrder;
    }
 
    public int ExecutionOrder { get; set; }
}
 
[Rule(2)]
public class DateDiscountRule : IRule
{
    public void Execute(IOrder order)
    {
        if (DateTime.Now.Month == 2)
        {
            order.Price -= 100;
        }
    }
}
 
[ImportMany(typeof(IRule))]
public IEnumerable<Lazy<IRule, IRuleMetadata>> Rules { get; set; }
by TheCodeJunkie
  February 13, 2010 @ 3:30pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate