Language: C#
MEF metadata view on custom export attribute
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; }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

