GetArgumentProperties() 공개 정적인 메소드

Gets all properties that have ArgumentAttribute's and returns then in a dictionary.
public static GetArgumentProperties ( Type type ) : ArgumentAttribute>.Dictionary
type System.Type
리턴 ArgumentAttribute>.Dictionary
예제 #1
0
        /// <summary>
        /// Writes out the argument syntax for the given arguments Type.
        /// </summary>
        public void WriteArgumentSyntax(Type argumentsType)
        {
            //  SAMPLE OUTPUT
            //
            //  -requiredArg req_value_name [-optionalArg1 value_name] [-optionalArg2 value_name]

            Dictionary <PropertyInfo, ArgumentAttribute> properties =
                CommandArguments.GetArgumentProperties(argumentsType);

            var syntax = new StringBuilder();

            int count = 0;

            foreach (var prop in properties)
            {
                bool optional = IsOptional(prop.Key);
                if (optional)
                {
                    syntax.Append("[");
                }

                syntax.Append("-");
                syntax.Append(prop.Value.ShortName);
                syntax.Append(" ");
                syntax.Append(prop.Value.ValueName ?? prop.Value.Name);

                if (optional)
                {
                    syntax.Append("]");
                }

                //  if not the last one, add a space
                if (count < properties.Count - 1)
                {
                    syntax.Append(" ");
                }

                count++;
            }

            _log.Write(syntax.ToString());
        }
예제 #2
0
        /// <summary>
        /// Writes out the list of arguments for the given arguments Type.
        /// </summary>
        public void WriteArgumentList(Type argumentsType)
        {
            //  SAMPLE OUTPUT
            //
            //  Options:
            //    -f, -firstArg       description of first argument
            //    -s, -secondArg      description of second argument

            _log.WriteLine(string.Empty);
            _log.WriteLine("Options:");

            Dictionary <PropertyInfo, ArgumentAttribute> properties =
                CommandArguments.GetArgumentProperties(argumentsType);

            int maxArgNameLength = properties.Max(x => x.Value.ShortName.Length + x.Value.Name.Length) + 4;

            foreach (var prop in properties)
            {
                _log.Write("".PadLeft(IndentWidth));
                _log.Write(string.Format("-{0}, -{1}", prop.Value.ShortName, prop.Value.Name).PadRight(maxArgNameLength + TabWidth));
                _log.WriteLine(prop.Value.Description);
            }
        }