PowerArgs.CommandLineArgumentsDefinition.FindCommandLineActions C# (CSharp) Method

FindCommandLineActions() private method

private FindCommandLineActions ( Type t ) : List
t System.Type
return List
        private List<CommandLineAction> FindCommandLineActions(Type t)
        {
            var knownAliases = new List<string>();
            foreach (var argument in Arguments) knownAliases.AddRange(argument.Aliases);

            BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public;

            var actions = (from p in t.GetProperties(flags)
                           where  CommandLineAction.IsActionImplementation(p)
                           select CommandLineAction.Create(p, knownAliases)).ToList();

            List<Type> typesToSearchForActions = new List<Type>() { t };

            if(t.HasAttr<ArgActionResolver>())
            {
                typesToSearchForActions.AddRange(t.Attr<ArgActionResolver>().ResolveActionTypes());
            }

            typesToSearchForActions.AddRange(t.Attrs<ArgActionType>().Select(aat => aat.ActionType));

            foreach (var typeToSearch in typesToSearchForActions)
            {
                var requireStatic = typeToSearch != t;
                foreach (var method in typeToSearch.GetMethods(flags).Where(m => CommandLineAction.IsActionImplementation(m)))
                {
                    if(requireStatic && method.IsStatic == false)
                    {
                        throw new InvalidArgDefinitionException("The method "+method.DeclaringType.FullName+"."+method.Name+" must be static because it has been imported using [ArgActionType] or [ArgActions]");
                    }

                    var action = CommandLineAction.Create(method, knownAliases.ToList());
                    var matchingPropertyBasedAction = actions.Where(a => a.Aliases.First() == action.Aliases.First()).SingleOrDefault();
                    if (matchingPropertyBasedAction != null) continue;
                    actions.Add(action);
                }
            }

            return actions;
        }