Exemplo n.º 1
0
        private string GetArgumentNameWithPrefix(ArgumentMap arg, bool includeTypeDesc = false, bool includeSampleValue = false)
        {
            string key       = null;
            var    shortName = arg.ShortName != null?arg.ShortName.ToString() : null;

            if (!string.IsNullOrWhiteSpace(shortName) && !string.IsNullOrWhiteSpace(arg.LongName))
            {
                key = "-" + arg.ShortName + ", --" + arg.LongName;
            }
            else if (!string.IsNullOrWhiteSpace(shortName))
            {
                key = "-" + arg.ShortName;
            }
            else if (!string.IsNullOrWhiteSpace(arg.LongName))
            {
                key = "--" + arg.LongName;
            }

            if (includeSampleValue)
            {
                var sample = this.GetExampleValueForType(arg.Type);
                if (sample != null)
                {
                    key = string.Format("{0}=<{1}>", key, sample);
                }
            }

            if (includeTypeDesc)
            {
                return(key + " (" + ReflectionHelper.CSharpName(arg.Type) + ")");
            }

            return(key);
        }
Exemplo n.º 2
0
        public static string GetMethodSpecification(ActionMap map)
        {
            var    format = "{0}({1})";
            string args   = null;

            foreach (var arg in map.ArgumentsMaps)
            {
                var typeName = ReflectionHelper.CSharpName(arg.Type);
                args += args == null ? typeName : ", " + typeName;
            }
            return(string.Format(format, map.ActionName, args));
        }
Exemplo n.º 3
0
        public static string GetMethodSpecification(ActionParsed parsed)
        {
            var    format = "{0}({1})";
            string args   = null;

            foreach (var map in parsed.ActionMap.ArgumentsMaps)
            {
                var typeName      = ReflectionHelper.CSharpName(map.Type);
                var value         = parsed.Arguments.First(f => f.Map == map);
                var valueWithDesc = value.GetArgumentNameInputted() + " = " + (string.IsNullOrWhiteSpace(value.Raw) ? "?" : value.Raw);
                args += args == null ? typeName + " " + valueWithDesc : ", " + typeName + " " + valueWithDesc;
            }
            return(string.Format(format, parsed.ActionMap.ActionName, args));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the formatted type name or if you are using the ObjectFile attribute,
        /// returns the value of the FileName property.
        /// </summary>
        /// <param name="type">Type reference to get name</param>
        /// <returns>Return a file name</returns>
        public string GetObjectFileName(Type type)
        {
            string fileName;

            var attr = type.GetCustomAttribute <ObjectFileAttribute>(true);

            if (attr != null && !string.IsNullOrWhiteSpace(attr.FileName))
            {
                fileName = attr.FileName;
            }
            else
            {
                fileName = ReflectionHelper.CSharpName(type, this.UseTypeFullName).Replace("<", "[").Replace(">", "]").Replace(@"\", "");
                fileName = this.DefaultFilePrefix + StringHelper.ToLowerSeparate(fileName, '.') + this.DefaultFileExtension;
            }

            return(fileName);
        }
Exemplo n.º 5
0
        public static string GetArgsDefinition(ArgumentMap arg)
        {
            var isDefault      = arg.IsOptional || arg.HasDefaultValue ? " = ?" : "";
            var typeName       = ReflectionHelper.CSharpName(arg.Type);
            var delimiterLong  = arg.LongName != null ? "--" + arg.LongName : "";
            var delimiterShort = arg.ShortName != null ? "-" + arg.ShortName : "";
            var delimiter      = "";

            if (delimiterLong != "" && delimiterShort != "")
            {
                delimiter = delimiterShort + "|" + delimiterLong;
            }
            else if (delimiterLong != "")
            {
                delimiter = delimiterLong;
            }
            else
            {
                delimiter = delimiterShort;
            }
            return(delimiter + isDefault);
        }