public static void ReflectType(Type type, string category = null) { category = category ?? ((FiltersAttribute)type.GetCustomAttributes(typeof(FiltersAttribute), true).FirstOrDefault())?.Category ?? type.Name; category = StringUtilities.RemoveNonLettersAndDigits(category); // Add to the documentation categoryDocs.TryRemove(category, out CategoryDoc whoCares); // Process the category doc through the event var categoryDoc = new CategoryDoc(type); var categoryDocLoadedEventArgs = new DocumentationEventArgs(categoryDoc); OnCategoryDocLoading(categoryDocLoadedEventArgs); if (!categoryDocLoadedEventArgs.Cancel) { // Add the processed category doc categoryDocs.TryAdd(category, categoryDocLoadedEventArgs.CategoryDoc); } foreach (var method in type.GetMethods().Where(m => m.GetCustomAttributes(typeof(FilterAttribute), true).Any())) { ReflectMethod(method, category, null); } }
public static void AddFilter(MethodInfo method, string category, string name, string description = null) { category = StringUtilities.RemoveNonLettersAndDigits(category); name = StringUtilities.RemoveNonLettersAndDigits(name); var fullyQualifiedCommandName = string.Concat(category, ".", name); // Check if it has any requirements foreach (RequiresAttribute dependency in method.GetCustomAttributes(typeof(RequiresAttribute), true)) { if (Type.GetType(dependency.TypeName) == null && !hiddenCommandMethods.ContainsKey(fullyQualifiedCommandName)) { // This dependency doesn't exist, so we're not going to load this command. // We're going to add this to the hidden commands dictionary, so we can give a more specific error message if this command is requested. hiddenCommandMethods.TryAdd(fullyQualifiedCommandName, string.Format(@"Command ""{0}"" could not be loaded due to a missing dependency on type ""{1}""", fullyQualifiedCommandName, dependency.TypeName)); return; } } // Process this through the event var commandEventArgs = new CommandEventArgs(fullyQualifiedCommandName, method); OnCommandLoading(commandEventArgs); if (commandEventArgs.Cancel) { // If they cancel, we just abandon and don't load the command, or the documentation return; } // Load the processed command commandMethods.TryRemove(commandEventArgs.FullyQualifiedCommandName.ToLower(), out MethodInfo discardCommandMethods); // Remove it if it exists already commandMethods.TryAdd(commandEventArgs.FullyQualifiedCommandName.ToLower(), commandEventArgs.Method); // Remove this if it exists commandDocs.TryRemove(fullyQualifiedCommandName, out CommandDoc discardCommandDocs); // Process the filter doc through the event var filterDoc = new CommandDoc(method, name, description); var filterDocLoadedEventArgs = new DocumentationEventArgs(filterDoc); OnFilterDocLoading(filterDocLoadedEventArgs); // Do they want to cancel? if (!filterDocLoadedEventArgs.Cancel) { // Add the processed filter doc commandDocs.TryAdd(fullyQualifiedCommandName, filterDocLoadedEventArgs.CommandDoc); } }
private static void OnCategoryDocLoading(DocumentationEventArgs e) => CategoryDocLoading?.Invoke(null, e);
private static void OnFilterDocLoading(DocumentationEventArgs e) => FilterDocLoading?.Invoke(null, e);