MakeReadable() public static method

Convert a type into a human readable string
public static MakeReadable ( Type type ) : string
type System.Type
return string
Example #1
0
        void MakeTokenString(Token token, IndentingStringBuilder sb, Stack <string> endTags)
        {
            string tagName;
            string keyAttr;

            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("</{0}>", endTags.Pop());
                break;

            case TokenType.SimpleFieldValue:
                tagName = TagName(token, out keyAttr);
                sb.AppendFormatLine("<{0}{1}>{2}</{0}>", tagName, keyAttr, Unquote(token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                tagName = TagName(token, out keyAttr);
                sb.AppendFormatLine("<{0}{1} ref='{2}'/>", tagName, keyAttr, token.ReferenceNo.Number);
                break;

            case TokenType.FieldnameWithTypeAndReference:
                var optionReferenceInfo = token.ReferenceNo != null
                      ? string.Format(" ref='{0}'", token.ReferenceNo.Number)
                      : "";

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType)
                                .Replace('<', '(')
                                .Replace('>', ')');
                tagName = TagName(token, out keyAttr);
                endTags.Push(tagName);
                sb.AppendFormatLine("<{0}{1} type='{2}'{3}>", tagName, keyAttr, fieldType, optionReferenceInfo);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #2
0
        public string Print(List <Token> tokens)
        {
            var sb      = new StringBuilder(tokens.Count * 7);
            var newline = configuration.NewLineDefinition;
            var count   = tokens.Count;

            for (int i = 0; i < count; i++)
            {
                var token = tokens[i];

                switch (token.Tokenkind)
                {
                case TokenType.StartScope:
                    sb.Append(newline);
                    break;

                case TokenType.StartList:
                case TokenType.StartDict:
                    sb.Append("[" + newline + "]");
                    break;

                case TokenType.EndScope:
                    sb.Append(configuration.NewLineDefinition);
                    break;

                case TokenType.EndList:
                case TokenType.EndDict:
                    sb.Append("]" + configuration.NewLineDefinition);
                    break;

                case TokenType.SimpleFieldValue:
                case TokenType.SeenBeforeWithReference:
                    sb.Append(token.Value);
                    break;

                case TokenType.FieldnameWithTypeAndReference:
                    var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);
                    sb.Append(MakeFieldValue(token, newline + "new (" + fieldType + ")"));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(sb.ToString());
        }
        void MakeTokenString(Token token, IndentingStringBuilder sb)
        {
            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.AppendFormatLine("{{");
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("}}");
                break;

            case TokenType.SimpleFieldValue:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, "-> " + token.ReferenceNo.Number));
                break;

            case TokenType.FieldnameWithTypeAndReference:
                var optionReferenceInfo = token.ReferenceNo == null
                      ? ""
                      : string.Format(", ref: {0}", token.ReferenceNo.Number);

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);

                string value = string.Format("new {0}(){1}", fieldType, optionReferenceInfo);
                sb.AppendFormatLine("{0}", MakeFieldValue(token, value));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #4
0
        void MakeTokenString(Token token, IndentingStringBuilder sb)
        {
            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.AppendFormatLine("{{");
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("}},");
                break;

            case TokenType.SimpleFieldValue:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                throw CreateCyclicalObjectGraphException();

            case TokenType.FieldnameWithTypeAndReference:
                if (token.ReferenceNo != null)
                {
                    throw CreateCyclicalObjectGraphException();
                }

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);

                string value = string.Format("new {0}{1}", fieldType, token.FieldType.IsArray ? "" : "()");
                sb.AppendFormatLine("{0}", MakeFieldValue(token, value));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }