public CommandEntity ParseMultiCommand(Type attribute) { CommandEntity command = new CommandEntity(); MultiCommandAttribute moduleAttribute = attribute.GetTypeInfo().GetCustomAttribute <MultiCommandAttribute>(); command = new MultiCommand(moduleAttribute.Entity as MultiCommand); object constructedInstance = null; try { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName), command); } catch { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName)); } List <Type> allChildren = attribute.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public) .Where((x) => x.GetTypeInfo().GetCustomAttributes <CommandEntityAttribute>().Any()) .ToList(); foreach (Type t in allChildren) { CommandEntityAttribute entityAttribute = t.GetTypeInfo().GetCustomAttribute <CommandEntityAttribute>(); CommandEntity entity = null; if (entityAttribute is MultiCommandAttribute cAttribute) { entity = ParseMultiCommand(t); } if (entity == null) { continue; } entity.Parent = command; command.Children.Add(entity); } List <MethodInfo> methods = attribute.GetMethods() .Where((x) => x.GetCustomAttributes <CommandAttribute>().Any()) .ToList(); foreach (MethodInfo m in methods) { Command newEvent = CreateCommand(m, command, constructedInstance); if (newEvent.IsDefault && (command as MultiCommand).defaultCommand == null) { (command as MultiCommand).defaultCommand = newEvent; } command.Children.Add(newEvent); } return(command); }
public CommandEntity GetChildrenFromModule(Type attribute) { CommandEntity module = new CommandEntity(); ModuleAttribute moduleAttribute = attribute.GetTypeInfo().GetCustomAttribute <ModuleAttribute>(); module = new Module(moduleAttribute.Entity as Module); object constructedInstance = null; List <Type> allChildren = attribute.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public) .Where((x) => x.GetTypeInfo().GetCustomAttributes <CommandEntityAttribute>().Any()) .ToList(); try { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName), module); } catch { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName)); } foreach (Type t in allChildren) { CommandEntityAttribute entityAttribute = t.GetTypeInfo().GetCustomAttribute <CommandEntityAttribute>(); CommandEntity entity = null; if (entityAttribute is ModuleAttribute mAttribute) { entity = GetChildrenFromModule(t); } else if (entityAttribute is MultiCommandAttribute cAttribute) { entity = ParseMultiCommand(t); } if (entity == null) { continue; } entity.Parent = module; module.Children.Add(entity); } List <MethodInfo> methods = attribute.GetMethods() .Where((x) => x.GetCustomAttributes <CommandAttribute>().Any()) .ToList(); foreach (MethodInfo m in methods) { module.Children.Add(CreateCommand(m, module, constructedInstance)); } return(module); }
public CommandEntity GetChildrenFromModule(Type attribute) { CommandEntity module = new CommandEntity(); ModuleAttribute moduleAttribute = attribute.GetTypeInfo().GetCustomAttribute <ModuleAttribute>(); module = new Module(moduleAttribute.Entity as Module); object constructedInstance = null; List <Type> allChildren = attribute.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public) .Where((x) => x.GetTypeInfo().GetCustomAttributes <CommandEntityAttribute>().Any()) .ToList(); try { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName), module); } catch { constructedInstance = Activator.CreateInstance(Type.GetType(attribute.AssemblyQualifiedName)); } foreach (Type t in allChildren) { CommandEntityAttribute entityAttribute = t.GetTypeInfo().GetCustomAttribute <CommandEntityAttribute>(); if (entityAttribute is ModuleAttribute mAttribute) { CommandEntity entity = GetChildrenFromModule(t); module = new Module(mAttribute.Entity as Module); entity.Parent = module; module.Children.Add(entity); } } List <MethodInfo> methods = attribute.GetMethods() .Where((x) => x.GetCustomAttributes <CommandAttribute>().Any()) .ToList(); foreach (MethodInfo m in methods) { CommandAttribute commandAttribute = m.GetCustomAttribute <CommandAttribute>(); Command newEvent = new Command(commandAttribute.Entity as Command); newEvent.ProcessCommand = async(context) => await(Task) m.Invoke(constructedInstance, new object[] { context }); newEvent.Parent = module; module.Children.Add(newEvent); } return(module); }