Create() статический приватный Метод

static private Create ( MethodInfo actionMethod, List knownAliases ) : CommandLineAction
actionMethod System.Reflection.MethodInfo
knownAliases List
Результат CommandLineAction
Пример #1
0
        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();

            if (t.HasAttr <ArgActionType>())
            {
                t = t.Attr <ArgActionType>().ActionType;
            }

            foreach (var action in t.GetMethods(flags).Where(m => CommandLineAction.IsActionImplementation(m)).Select(m => CommandLineAction.Create(m, knownAliases.ToList())))
            {
                var matchingPropertyBasedAction = actions.Where(a => a.Aliases.First() == action.Aliases.First()).SingleOrDefault();
                if (matchingPropertyBasedAction != null)
                {
                    continue;
                }
                actions.Add(action);
            }

            return(actions);
        }
Пример #2
0
        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);
        }