PowerArgs.CommandLineArgument.FindDefaultShortcuts C# (CSharp) Method

FindDefaultShortcuts() static private method

static private FindDefaultShortcuts ( PropertyInfo info, List knownShortcuts, bool ignoreCase ) : List
info System.Reflection.PropertyInfo
knownShortcuts List
ignoreCase bool
return List
        internal static List<string> FindDefaultShortcuts(PropertyInfo info, List<string> knownShortcuts, bool ignoreCase)
        {
            List<string> ret = new List<string>();

            bool excludeName = info.Attrs<ArgShortcut>().Where(s => s.Policy == ArgShortcutPolicy.ShortcutsOnly).Count() > 0;

            if (excludeName == false)
            {
                knownShortcuts.Add(info.Name);

                if (CommandLineAction.IsActionImplementation(info) && info.Name.EndsWith(Constants.ActionArgConventionSuffix))
                {
                    ret.Add(info.Name.Substring(0, info.Name.Length - Constants.ActionArgConventionSuffix.Length));
                }
                else
                {
                    ret.Add(info.Name);
                }
            }

            var attrs = info.Attrs<ArgShortcut>();

            if (attrs.Count == 0)
            {
                var shortcut = GenerateShortcutAlias(info.Name, knownShortcuts, ignoreCase);
                if (shortcut != null)
                {
                    knownShortcuts.Add(shortcut);
                    ret.Add(shortcut);
                }

                return ret;
            }
            else
            {
                return ret;
            }
        }

Usage Example

        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);
        }