当前位置: 首页>>代码示例>>C#>>正文


C# StringBuilder.Indent方法代码示例

本文整理汇总了C#中StringBuilder.Indent方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Indent方法的具体用法?C# StringBuilder.Indent怎么用?C# StringBuilder.Indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringBuilder的用法示例。


在下文中一共展示了StringBuilder.Indent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DumpArray

        public static string DumpArray(Array array)
        {
            var builder = new StringBuilder();

            if (array.Length == 0)
            {
                builder.Indent("[]");
                return builder.ToString();
            }

            return builder.ToString();
        }
开发者ID:FirehaK,项目名称:CoCSharp,代码行数:12,代码来源:PacketLogger.cs

示例2: BuildStructToString

        private string BuildStructToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Indent(level).Append("public override string ToString() {").AppendLine();
            IndentUp();

            sb.Indent(level).Append("StringBuilder __sb = new StringBuilder(\"").Append(Name).Append("(\");").AppendLine();

            Fields.Sort();

            sb.Indent(level).Append("bool __first = true;").AppendLine();

            foreach(var field in Fields)
            {
                sb.Indent(level).Append("if (").Append(field.CSharpPropertyName).Append(" != null) {").AppendLine();
                IndentUp();
                sb.Indent(level).Append("if(!__first) { __sb.Append(\", \"); }").AppendLine();
                sb.Indent(level).Append("__first = false;").AppendLine();
                sb.Indent(level).Append("__sb.Append(\"").Append(field.CSharpPropertyName).Append(": \");").AppendLine();

                if (field.GenType.IsStruct)
                {
                    sb.Indent(level).Append("__sb.Append(").Append(field.CSharpPropertyName).Append("== null ? \"<null>\" : ")
                        .Append(field.CSharpPropertyName).Append(".ToString());").AppendLine();
                }
                else
                {
                    sb.Indent(level).Append("__sb.Append(").Append(field.CSharpPropertyName).Append(");").AppendLine();
                }

                IndentDown();
                sb.Indent(level).Append("}").AppendLine();
            }

            sb.Indent(level).Append("__sb.Append(\")\");").AppendLine();
            sb.Indent(level).Append("return __sb.ToString();").AppendLine();

            IndentDown();
            sb.Indent(level).Append("}").AppendLine().AppendLine();

            return sb.ToString();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:43,代码来源:StructContext.cs

示例3: BuildSerializeContainer

        private void BuildSerializeContainer(StringBuilder sb, string prefix, GenType genType)
        {
            ScopeUp(sb);

            if (genType.IsMap)
            {
                sb.Indent(level).Append("oprot.WriteMapBegin(new TMap(").Append(genType.KeyType.TTypeName).Append(", ");
                sb.Append(genType.ValueType.TTypeName).Append(", ").Append(prefix).Append(".Count));").AppendLine();
            }
            else if (genType.IsSet)
            {
                sb.Indent(level).Append("oprot.WriteSetBegin(new TSet(").Append(genType.ElementType.TTypeName).Append(", ");
                sb.Append(prefix).Append(".Count));").AppendLine();
            }
            else if (genType.IsList)
            {
                sb.Indent(level).Append("oprot.WriteListBegin(new TList(").Append(genType.ElementType.TTypeName).Append(", ");
                sb.Append(prefix).Append(".Count));").AppendLine();
            }

            string iter = Tmp("_iter");
            if (genType.IsMap)
            {
                sb.Indent(level).Append("foreach (").Append(genType.KeyType.CSharpTypeName).Append(" ").Append(iter).Append(" in ").Append(prefix).Append(".Keys)").AppendLine();
            }
            else if (genType.IsSet || genType.IsList)
            {
                sb.Indent(level).Append("foreach (").Append(genType.ElementType.CSharpTypeName).Append(" ").Append(iter).Append(" in ").Append(prefix).Append(")").AppendLine();
            }

            ScopeUp(sb);

            if (genType.IsMap)
            {
                BuildSerializeMapElement(sb, genType, iter, prefix);
            }
            else if (genType.IsSet)
            {
                BuildSerializeSetElement(sb, genType, iter);
            }
            else if (genType.IsList)
            {
                BuildSerializeListElement(sb, genType, iter);
            }

            ScopeDown(sb);

            if (genType.IsMap)
            {
                sb.Indent(level).AppendLine("oprot.WriteMapEnd();");
            }
            else if (genType.IsSet)
            {
                sb.Indent(level).AppendLine("oprot.WriteSetEnd();");
            }
            else if (genType.IsList)
            {
                sb.Indent(level).AppendLine("oprot.WriteListEnd();");
            }

            ScopeDown(sb);
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:62,代码来源:StructContext.cs

示例4: BuildSerializeStruct

 private void BuildSerializeStruct(StringBuilder sb, string prefix)
 {
     sb.Indent(level).Append(prefix).Append(".Write(oprot);").AppendLine();
 }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:4,代码来源:StructContext.cs

示例5: ScopeDown

 private void ScopeDown(StringBuilder sb)
 {
     level--;
     sb.Indent(level).AppendLine("}");
 }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:5,代码来源:StructContext.cs

示例6: DumpCommandArray

        private static string DumpCommandArray(ICommand[] cmds)
        {
            var builder = new StringBuilder();

            if (cmds.Length == 0)
                builder.Append("Empty");

            for (int i = 0; i < cmds.Length; i++)
            {
                var cmdType = cmds[i].GetType();
                var cmdName = cmdType.Name;
                var cmdFields = cmdType.GetFields();

                builder.Append(cmdName);
                builder.Indent("[");
                builder.AppendLine();

                for (int k = 0; k < cmdFields.Length; k++)
                {
                    var field = cmdFields[i];
                    var fieldName = field.Name;
                    var fieldValue = field.GetValue(cmds[i]);

                    if (field.IsPrivate)
                        continue;

                    builder.Indent();
                    builder.AppendFormat("{0}: ", fieldName);

                    if (fieldValue == null) builder.Append("null");
                    else if (fieldValue is string) builder.AppendFormat("{0}{1}{2}", "\"", fieldValue, "\"");
                    else if (fieldValue is ICommand[])
                    {
                        var cmd = fieldValue as ICommand[];
                        builder.Append(DumpCommandArray(cmd));
                    }
                    else if (fieldValue is byte[])
                    {
                        var byteArray = fieldValue as byte[];
                        builder.AppendLine();
                        builder.Append(DumpByteArray(byteArray));
                    }
                    else builder.Append(fieldValue);
                    builder.AppendLine();
                }

                builder.AppendLine();
                builder.Indent("]");
            }
            return builder.ToString();
        }
开发者ID:jibinthomas007,项目名称:CoCSharp,代码行数:51,代码来源:PacketLogger.cs

示例7: BuildDeserializeListElement

        private void BuildDeserializeListElement(StringBuilder sb, GenType listType, string prefix = "")
        {
            string elem = Tmp("_elem");

            var felem = new FieldContext(elem, listType.ElementType);

            sb.Indent(level).Append(DeclareField(felem, true)).AppendLine();

            BuildDeserializeField(sb, felem);

            sb.Indent(level).Append(prefix).Append(".Add(").Append(elem).Append(");").AppendLine();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:12,代码来源:StructContext.cs

示例8: BuildStructReader

        private string BuildStructReader()
        {
            StringBuilder sb = new StringBuilder();
            tempNum = 0;
            sb.Indent(level).AppendLine("public void Read(TProtocol iprot)");
            ScopeUp(sb);

            Fields.Sort();

            sb.Indent(level).Append("TField field;").AppendLine();
            sb.Indent(level).Append("iprot.ReadStructBegin();").AppendLine();
            sb.Indent(level).Append("while (true)").AppendLine();
            ScopeUp(sb);

            sb.Indent(level).Append("field = iprot.ReadFieldBegin();").AppendLine();

            sb.Indent(level).Append("if (field.Type == TType.Stop) { ").AppendLine();
            IndentUp();
            sb.Indent(level).Append("break;").AppendLine();
            IndentDown();
            sb.Indent(level).Append("}").AppendLine();

            sb.Indent(level).Append("switch (field.ID)").AppendLine();

            ScopeUp(sb);

            foreach (var field in Fields)
            {
                sb.Indent(level).Append("case ").Append(field.Id).Append(":").AppendLine();
                IndentUp();
                sb.Indent(level).Append("if (field.Type == ").Append(field.GenType.TTypeName).Append(") {").AppendLine();
                IndentUp();

                BuildDeserializeField(sb, field);

                IndentDown();
                sb.Indent(level).Append("} else {").AppendLine();
                sb.Indent(level).Append("    TProtocolUtil.Skip(iprot, field.Type);").AppendLine();
                sb.Indent(level).Append("}").AppendLine();
                sb.Indent(level).Append("break;").AppendLine();
                IndentDown();
            }

            sb.Indent(level).Append("default:").AppendLine();
            IndentUp();
            sb.Indent(level).Append("TProtocolUtil.Skip(iprot, field.Type);").AppendLine();
            sb.Indent(level).Append("break;").AppendLine();
            IndentDown();

            ScopeDown(sb);

            sb.Indent(level).Append("iprot.ReadFieldEnd();").AppendLine();

            ScopeDown(sb);

            sb.Indent(level).Append("iprot.ReadStructEnd();").AppendLine();

            foreach (var field in Fields)
            {
                // validation
                if (field.Required)
                {
                    sb.Indent(level).Append("if (").Append(field.CSharpPropertyName).Append(" == null)").AppendLine();
                    IndentUp();
                    sb.Indent(level).Append("throw new TProtocolException(TProtocolException.INVALID_DATA, \"missing required property '").Append(field.CSharpPropertyName).Append("'\");").AppendLine();
                    IndentDown();
                }
            }

            IndentDown();

            sb.Indent(level).Append("}").AppendLine().AppendLine();

            return sb.ToString();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:75,代码来源:StructContext.cs

示例9: BuildDeserializeContainer

        private void BuildDeserializeContainer(StringBuilder sb, GenType genType, string prefix = "")
        {
            ScopeUp(sb);

            string obj;

            if (genType.IsMap)
            {
                obj = Tmp("_map");
            }
            else if (genType.IsSet)
            {
                obj = Tmp("_set");
            }
            else
            {
                obj = Tmp("_list");
            }

            sb.Indent(level).Append(prefix).Append(" = new ").Append(genType.CSharpTypeName).Append("();").AppendLine();
            if (genType.IsMap)
            {
                sb.Indent(level).Append("TMap ").Append(obj).Append(" = iprot.ReadMapBegin();").AppendLine();
            }
            else if (genType.IsSet)
            {
                sb.Indent(level).Append("TSet ").Append(obj).Append(" = iprot.ReadSetBegin();").AppendLine();
            }
            else
            {
                sb.Indent(level).Append("TList ").Append(obj).Append(" = iprot.ReadListBegin();").AppendLine();
            }

            string i = Tmp("_i");
            sb.Indent(level).Append("for(int ").Append(i).Append(" = 0; ").Append(i).Append(" < ").Append(obj).Append(".Count").Append("; ").Append("++").Append(i).Append(")").AppendLine();
            ScopeUp(sb);

            if (genType.IsMap)
            {
                BuildDeserializeMapElement(sb, genType, prefix);
            }
            else if (genType.IsSet)
            {
                BuildDeserializeSetElement(sb, genType, prefix);
            }
            else if (genType.IsList)
            {
                BuildDeserializeListElement(sb, genType, prefix);
            }

            ScopeDown(sb);

            if (genType.IsMap)
            {
                sb.Indent(level).Append("iprot.ReadMapEnd();").AppendLine();
            }
            else if (genType.IsSet)
            {
                sb.Indent(level).Append("iprot.ReadSetEnd();").AppendLine();
            }
            else if (genType.IsList)
            {
                sb.Indent(level).Append("iprot.ReadListEnd();").AppendLine();
            }

            ScopeDown(sb);
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:67,代码来源:StructContext.cs

示例10: BuildDeserializeMapElement

        private void BuildDeserializeMapElement(StringBuilder sb, GenType mapType, string prefix = "")
        {
            string key = Tmp("_key");
            string val = Tmp("_val");

            var fkey = new FieldContext(key, mapType.KeyType);
            var fval = new FieldContext(val, mapType.ValueType);

            sb.Indent(level).Append(DeclareField(fkey)).AppendLine();
            sb.Indent(level).Append(DeclareField(fval)).AppendLine();

            BuildDeserializeField(sb, fkey);
            BuildDeserializeField(sb, fval);

            sb.Indent(level).Append(prefix).Append("[").Append(key).Append("] = ").Append(val).Append(";").AppendLine();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:16,代码来源:StructContext.cs

示例11: BuildDeserializeStruct

 private void BuildDeserializeStruct(StringBuilder sb, string name, string prefix = "")
 {
     sb.Indent(level).Append(prefix).Append(" = new ").Append(name).Append("();").AppendLine();
     sb.Indent(level).Append(prefix).Append(".Read(iprot);").AppendLine();
 }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:5,代码来源:StructContext.cs

示例12: BuildDeserializeField

        private void BuildDeserializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isPropertyless = false)
        {
            var genType = field.GenType;

            string name = prefix + (isPropertyless ? "" : PropertyNameFromField(field));

            if (genType.IsStruct)
            {
                BuildDeserializeStruct(sb, genType.CSharpTypeName, name);
            }
            else if (genType.IsContainer)
            {
                BuildDeserializeContainer(sb, genType, name);
            }
            else if (genType.IsBaseType || genType.IsEnum)
            {
                sb.Indent(level).Append(name).Append(" = ");

                if (genType.IsEnum)
                {
                    sb.Append("(").Append(genType.CSharpTypeName).Append(")");
                }

                sb.Append("iprot.");

                if (genType.IsBaseType)
                {
                    switch (genType.GType)
                    {
                        case GType.Binary:
                            sb.Append("ReadBinary();");
                            break;
                        case GType.String:
                            sb.Append("ReadString();");
                            break;
                        case GType.Bool:
                            sb.Append("ReadBool();");
                            break;
                        case GType.Byte:
                            sb.Append("ReadByte();");
                            break;
                        case GType.I16:
                            sb.Append("ReadI16();");
                            break;
                        case GType.I32:
                            sb.Append("ReadI32();");
                            break;
                        case GType.I64:
                            sb.Append("ReadI64();");
                            break;
                        case GType.Double:
                            sb.Append("ReadDouble();");
                            break;
                        default:
                            throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE BASE TYPE {0}", genType.GType));
                    }
                }
                else if (genType.IsEnum)
                {
                    sb.Append("ReadI32();");
                }
                sb.AppendLine();
            }
            else
            {
                throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE FIELD {0} TYPE {1}", field.Name, genType.CSharpTypeName));
            }
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:68,代码来源:StructContext.cs

示例13: BuildSerializeField

        private void BuildSerializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isElement = false, bool isFieldLess = false)
        {
            var genType = field.GenType;
            var name = prefix + (isFieldLess ? "" : FieldNameFromField(field));
            if (genType.IsStruct)
            {
                BuildSerializeStruct(sb, name);
            }
            else if (genType.IsContainer)
            {
                BuildSerializeContainer(sb, name, genType);
            }
            else if (genType.IsBaseType || genType.IsEnum)
            {
                sb.Indent(level).Append("oprot.");

                if (genType.IsBaseType)
                {
                    switch (genType.GType)
                    {
                        case GType.Binary:
                            sb.Append("writeBinary(").Append(name).Append(");");
                            break;
                        case GType.String:
                            sb.Append("writeString(").Append(name).Append(");");
                            break;
                        case GType.Bool:
                            sb.Append("writeBool(").Append(name).Append(".booleanValue());");
                            break;
                        case GType.Byte:
                            sb.Append("writeByte(").Append(name).Append(".byteValue());");
                            break;
                        case GType.I16:
                            sb.Append("writeI16(").Append(name).Append(".shortValue());");
                            break;
                        case GType.I32:
                            sb.Append("writeI32(").Append(name).Append(".intValue());"); ;
                            break;
                        case GType.I64:
                            sb.Append("writeI64(").Append(name).Append(".longValue());");
                            break;
                        case GType.Double:
                            sb.Append("writeDouble(").Append(name).Append(".doubleValue());"); ;
                            break;
                        default:
                            throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE BASE TYPE {0}", genType.GType));
                    }
                }
                else if (genType.IsEnum)
                {
                    sb.Append("writeI32(").Append(name).Append(".getValue());");
                }
                sb.AppendLine();
            }
            else
            {
                throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE {0} TYPE {1}", field.Name, genType.JavaTypeName));
            }
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:59,代码来源:StructContext.cs

示例14: BuildStructEquals

        private string BuildStructEquals()
        {
            StringBuilder sb = new StringBuilder();

            sb.Indent(level).Append("public override bool Equals(object that) {").AppendLine();
            IndentUp();

            sb.Indent(level).Append("var other = that as ").Append(CSharpName).Append(";").AppendLine();
            sb.Indent(level).Append("if (other == null) return false;").AppendLine();
            sb.Indent(level).Append("if (ReferenceEquals(this, other)) return true;").AppendLine();

            Fields.Sort();

            bool first = true;

            foreach (var field in Fields)
            {
                if (first)
                {
                    first = false;
                    sb.Indent(level).Append("return ");
                    IndentUp();
                }
                else
                {
                    sb.AppendLine();
                    sb.Indent(level).Append("&& ");
                }

                if (field.GenType.IsContainer)
                {
                    sb.Append("TCollections.Equals(");
                    sb.Append(field.CSharpPropertyName).Append(", other.").Append(field.CSharpPropertyName).Append(")");
                }
                else if (field.GenType.IsBinary)
                {
                    sb.Append("(").Append(field.CSharpPropertyName).Append(" == null ? other.").Append(field.CSharpPropertyName).
                       Append(" == null : ").Append(field.CSharpPropertyName).Append(".SequenceEqual(other.").
                       Append(field.CSharpPropertyName).Append("))");
                }
                else
                {
                    sb.Append("System.Object.Equals(");
                    sb.Append(field.CSharpPropertyName).Append(", other.").Append(field.CSharpPropertyName).Append(")");
                }
            }
            if (first)
            {
                sb.Indent(level).Append("return true;").AppendLine();
            }
            else
            {
                sb.AppendLine(";");
                IndentDown();
            }

            IndentDown();
            sb.Indent(level).Append("}").AppendLine().AppendLine();

            return sb.ToString();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:61,代码来源:StructContext.cs

示例15: BuildStructWriter

        private string BuildStructWriter()
        {
            StringBuilder sb = new StringBuilder();
            tempNum = 0;
            sb.Indent(level).AppendLine("public void Write(TProtocol oprot) {");
            IndentUp();

            Fields.Sort();

            sb.Indent(level).Append("TStruct struc = new TStruct(\"").Append(Name).AppendLine("\");");
            sb.Indent(level).AppendLine("oprot.WriteStructBegin(struc);");

            if (Fields.Count > 0)
            {
                // validation
                foreach (var field in Fields)
                {
                    if (field.Required)
                    {
                        sb.Indent(level).Append("if (").Append(field.CSharpPropertyName).Append(" == null)").AppendLine();
                        IndentUp();
                        sb.Indent(level).Append("throw new TProtocolException(TProtocolException.INVALID_DATA, \"missing required property '").Append(field.CSharpPropertyName).Append("'\");").AppendLine();
                        IndentDown();
                    }
                }

                sb.Indent(level).AppendLine("TField field = new TField();");

                foreach (var field in Fields)
                {
                    sb.Indent(level).Append("if (").Append(field.CSharpPropertyName).AppendLine(" != null) {");
                    IndentUp();
                    sb.Indent(level).Append("field.Name = ").Append("\"").Append(field.Name).AppendLine("\";");
                    sb.Indent(level).Append("field.Type = ").Append(field.GenType.TTypeName).AppendLine(";");
                    sb.Indent(level).Append("field.ID = ").Append(field.Id).AppendLine(";");
                    sb.Indent(level).Append("oprot.WriteFieldBegin(field);").AppendLine();

                    BuildSerializeField(sb, field);

                    sb.Indent(level).Append("oprot.WriteFieldEnd();").AppendLine();
                    IndentDown();
                    sb.Indent(level).AppendLine("}");
                }
            }

            sb.Indent(level).AppendLine("oprot.WriteFieldStop();");
            sb.Indent(level).AppendLine("oprot.WriteStructEnd();");
            IndentDown();
            sb.Indent(level).AppendLine("}").AppendLine().AppendLine();

            return sb.ToString();
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:52,代码来源:StructContext.cs


注:本文中的StringBuilder.Indent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。