public void RegisterProcessor(Type processor) { ProcessorAttribute attr = Attribute.GetCustomAttribute(processor, typeof(ProcessorAttribute)) as ProcessorAttribute; if (attr != null && !processors.ContainsKey(attr.ProcessorName)) { ProcessorInfo info = new ProcessorInfo(attr, processor); processors.Add(attr.ProcessorName, info); } }
public void Dispose() { mAttributes = null; }
/// <summary> /// Initializes a new instance of the <see cref="Processor" /> class. /// </summary> /// <param name="type">The type.</param> /// <param name="processorAttribute">The processor attribute.</param> public Processor(Type type, ProcessorAttribute processorAttribute) { this.type = type; this.ProcessorAttribute = processorAttribute; }
private ConsoleMenu GetConsoleMenu() { List <Type> processorTypes = new AssemblyScanner() .GetTypesWithAttribute <ProcessorAttribute>() .OrderBy(t => t.Name) .ToList(); var consoleMenuItems = new List <ConsoleMenuItem>(); List <string> categories = processorTypes .Select(t => { ProcessorAttribute processorAttribute = (ProcessorAttribute)t.GetCustomAttributes(typeof(ProcessorAttribute), true).Single(); return(processorAttribute.Category ?? GetDefaultCategory(t)); }) .OrderBy(s => s) .Distinct() .ToList(); for (int i = 0; i < categories.Count; i++) { string key = (i + 1).ToString(); string name = categories[i]; var subMenuItems = new List <ConsoleSubMenuItem>(); List <Type> processorTypesMatched = processorTypes .Where(t => { ProcessorAttribute processorAttr = (ProcessorAttribute)t.GetCustomAttributes(typeof(ProcessorAttribute), true).Single(); return((processorAttr.Category ?? GetDefaultCategory(t)) == name); }) .ToList(); for (int j = 0; j < processorTypesMatched.Count; j++) { Type t = processorTypesMatched[j]; ProcessorAttribute processorAttr = (ProcessorAttribute)t.GetCustomAttributes(typeof(ProcessorAttribute), true).Single(); string k = processorAttr.Key ?? (j + 1).ToString(); string n = processorAttr.Name ?? t.Name; k = ToSingleCharacter(k); var menuItem = new ConsoleSubMenuItem(k, n, t); subMenuItems.Add(menuItem); } key = ToSingleCharacter(key); var consoleMenuItem = new ConsoleMenuItem(key, name, subMenuItems); consoleMenuItems.Add(consoleMenuItem); } return(new ConsoleMenu(consoleMenuItems)); }