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


C# IndentedStringBuilder.Append方法代码示例

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


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

示例1: SerializeCompositeType

        private static string SerializeCompositeType(this CompositeType composite, IScopeProvider scope, string objectReference, 
            string valueReference, bool isRequired, Dictionary<Constraint, string> constraints, string modelReference = "client._models", bool serializeInnerTypes = false)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var builder = new IndentedStringBuilder("  ");
            var escapedObjectReference = objectReference.EscapeSingleQuotes();

            builder.AppendLine("if ({0}) {{", objectReference).Indent();
            builder = composite.AppendConstraintValidations(objectReference, constraints, builder);
            if (!string.IsNullOrEmpty(composite.PolymorphicDiscriminator))
            {
                builder.AppendLine("if({0}['{1}'] !== null && {0}['{1}'] !== undefined && {2}.discriminators[{0}['{1}']]) {{",
                                    objectReference,
                                    composite.PolymorphicDiscriminator, modelReference)
                    .Indent();
                if (!serializeInnerTypes) builder = ConstructBasePropertyCheck(builder, valueReference);
                builder.AppendLine("{0} = {1}.serialize();", valueReference, objectReference)
                    .Outdent()
                    .AppendLine("}} else {{", valueReference)
                    .Indent()
                        .AppendLine("throw new Error('No discriminator field \"{0}\" was found in parameter \"{1}\".');",
                                    composite.PolymorphicDiscriminator,
                                    escapedObjectReference)
                    .Outdent()
                    .AppendLine("}");
            }
            else
            {
                if (!serializeInnerTypes) builder = ConstructBasePropertyCheck(builder, valueReference);
                builder.AppendLine("{0} = {1}.serialize();", valueReference, objectReference);
            }
            builder.Outdent().AppendLine("}");

            if (isRequired)
            {
                builder.Append(" else {")
                    .Indent()
                        .AppendLine("throw new Error('{0} cannot be null or undefined.');", escapedObjectReference)
                    .Outdent()
                    .AppendLine("}");
            }
            return builder.ToString();
        }
开发者ID:maxkeller,项目名称:autorest,代码行数:47,代码来源:ClientModelExtensions.cs

示例2: ValidateEnumType

        private static string ValidateEnumType(this EnumType enumType, IScopeProvider scope, string valueReference, bool isRequired)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var builder = new IndentedStringBuilder("  ");
            var allowedValues = scope.GetVariableName("allowedValues");

            builder.AppendLine("if ({0}) {{", valueReference)
                        .Indent()
                            .AppendLine("var {0} = {1};", allowedValues, enumType.GetEnumValuesArray())
                            .AppendLine("if (!{0}.some( function(item) {{ return item === {1}; }})) {{", allowedValues, valueReference)
                            .Indent()
                                .AppendLine("throw new Error({0} + ' is not a valid value. The valid values are: ' + {1});", valueReference, allowedValues)
                            .Outdent()
                            .AppendLine("}")
                        .Outdent()
                        .AppendLine("}");
            if (isRequired)
            {
                builder.Append(" else {")
                    .Indent()
                        .AppendLine("throw new Error('{0} cannot be null or undefined.');", valueReference)
                    .Outdent()
                    .AppendLine("}");
            }

            return builder.ToString();
        }
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:31,代码来源:ClientModelExtensions.cs

示例3: ValidateCompositeType

        private static string ValidateCompositeType(this CompositeType composite, IScopeProvider scope, string valueReference, bool isRequired, string modelReference = "client._models")
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var builder = new IndentedStringBuilder("  ");
            var escapedValueReference = valueReference.EscapeSingleQuotes();

            builder.AppendLine("if ({0}) {{", valueReference).Indent();

            if (!string.IsNullOrEmpty(composite.PolymorphicDiscriminator))
            {
                builder.AppendLine("if({0}['{1}'] !== null && {0}['{1}'] !== undefined && {2}.discriminators[{0}['{1}']]) {{",
                                    valueReference,
                                    composite.PolymorphicDiscriminator, modelReference)
                    .Indent()
                        .AppendLine("{2}.discriminators[{0}['{1}']].validate({0});",
                            valueReference,
                            composite.PolymorphicDiscriminator, modelReference)
                    .Outdent()
                    .AppendLine("}} else {{", valueReference)
                    .Indent()
                        .AppendLine("throw new Error('No discriminator field \"{0}\" was found in parameter \"{1}\".');",
                                    composite.PolymorphicDiscriminator,
                                    escapedValueReference)
                    .Outdent()
                    .AppendLine("}");
            }
            else
            {
                builder.AppendLine("{2}['{0}'].validate({1});", composite.Name, valueReference, modelReference);
            }
            builder.Outdent().AppendLine("}");

            if (isRequired)
            {
                builder.Append(" else {")
                    .Indent()
                        .AppendLine("throw new Error('{0} cannot be null or undefined.');", escapedValueReference)
                    .Outdent()
                    .AppendLine("}");
            }
            return builder.ToString();
        }
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:46,代码来源:ClientModelExtensions.cs

示例4: SerializeEnumType

        private static string SerializeEnumType(this EnumType enumType, IScopeProvider scope, string objectReference, string valueReference, bool isRequired)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var builder = new IndentedStringBuilder("  ");
            var allowedValues = scope.GetVariableName("allowedValues");
            string tempReference = objectReference;
            builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", objectReference)
                        .Indent()
                        .AppendLine("var {0} = {1};", allowedValues, enumType.GetEnumValuesArray());
                        if (objectReference.IndexOfAny(new char[] { '.', '[', ']'}) >= 0)
                        {
                            tempReference = tempReference.NormalizeValueReference();
                            builder.AppendLine("var {0} = {1};", tempReference, objectReference);
                        }
                        builder.AppendLine("if (!{0}.some( function(item) {{ return item === {1}; }})) {{", allowedValues, tempReference)
                                    .Indent()
                                    .AppendLine("throw new Error({0} + ' is not a valid value. The valid values are: ' + {1});", objectReference, allowedValues)
                                .Outdent()
                                .AppendLine("}");
                        builder = ConstructBasePropertyCheck(builder, valueReference);
                        builder.AppendLine("{0} = {1};", valueReference, objectReference)
                              .Outdent()
                              .AppendLine("}");
            if (isRequired)
            {
                builder.Append(" else {")
                    .Indent()
                        .AppendLine("throw new Error('{0} cannot be null or undefined.');", objectReference)
                    .Outdent()
                    .AppendLine("}");
            }

            return builder.ToString();
        }
开发者ID:BretJohnson,项目名称:autorest,代码行数:38,代码来源:ClientModelExtensions.cs


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