using System; using System.Collections.Generic; using System.Reflection; using Chernobyl.Reflection; namespace Chernobyl.Attribution { /// /// A type that is derived from by types that are /// capable of performing a task on the /// they are applied to. /// /// The /// type that /// is capable of processing. public interface IProcessAttribute where TCustomAttributeProvider : ICustomAttributeProvider { /// /// Performs the task requested on the /// passed in. /// /// The /// this was applied to and that is to be /// processed. void Process(TCustomAttributeProvider attributeProvider); } /// /// Extensions and utility methods for the /// . /// public static class ProcessAttributeExtensions { /// /// Retrieves the /// instances from the provided /// and then invokes /// /// on each one, providing the as /// the argument. /// /// The type of the /// that is to have it's /// processed. /// The type of the /// and to /// retrieve from the for processing. /// The instance to pull the /// instance from for processing. /// True if this instance should look up the /// hierarchy chain of each method for . public static void Process( this TCustomAttributeProvider attributeProvider, bool inherited) where TCustomAttributeProvider : ICustomAttributeProvider where TProcessAttribute : IProcessAttribute { foreach (TProcessAttribute processTypeAttribute in attributeProvider.GetCustomAttributes(inherited)) processTypeAttribute.Process(attributeProvider); } /// /// Performs the task requested on the /// passed in. /// /// The type of the /// that is to be processed. /// The /// instances that are to be processed. /// True if this instance should look up the /// hierarchy chain of each method for /// . public static void Process( this IEnumerable attributeProviders, bool inherited) where TCustomAttributeProvider : ICustomAttributeProvider { foreach (TCustomAttributeProvider provider in attributeProviders) provider.Process>(inherited); } } }