PowerArgs.CommandLineAction.Create C# (CSharp) Method

Create() static private method

static private Create ( PropertyInfo actionProperty, List knownAliases ) : CommandLineAction
actionProperty System.Reflection.PropertyInfo
knownAliases List
return CommandLineAction
        internal static CommandLineAction Create(PropertyInfo actionProperty, List<string> knownAliases)
        {
            var ret = PropertyInitializer.CreateInstance<CommandLineAction>();
            ret.ActionMethod = ArgAction.ResolveMethod(actionProperty.DeclaringType, actionProperty);
            ret.Source = actionProperty;
            ret.Arguments.AddRange(new CommandLineArgumentsDefinition(actionProperty.PropertyType).Arguments);
            ret.IgnoreCase = true;

            if (actionProperty.DeclaringType.HasAttr<ArgIgnoreCase>() && actionProperty.DeclaringType.Attr<ArgIgnoreCase>().IgnoreCase == false)
            {
                ret.IgnoreCase = false;
            }

            if (actionProperty.HasAttr<ArgIgnoreCase>() && actionProperty.Attr<ArgIgnoreCase>().IgnoreCase == false)
            {
                ret.IgnoreCase = false;
            }

            ret.Metadata.AddRange(actionProperty.Attrs<IArgMetadata>().AssertAreAllInstanceOf<ICommandLineActionMetadata>());

            // This line only calls into CommandLineArgument because the code to strip 'Args' off the end of the
            // action property name lives here.  This is a pre 2.0 hack that's only left in place to support apps that
            // use the 'Args' suffix pattern.
            ret.Aliases.AddRange(CommandLineArgument.FindDefaultShortcuts(actionProperty, knownAliases, ret.IgnoreCase));

            return ret;
        }

Same methods

CommandLineAction::Create ( MethodInfo actionMethod, List knownAliases ) : CommandLineAction

Usage Example

Beispiel #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);
        }
All Usage Examples Of PowerArgs.CommandLineAction::Create