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


C# Utilities.IndentedStringBuilder类代码示例

本文整理汇总了C#中AutoRest.Core.Utilities.IndentedStringBuilder的典型用法代码示例。如果您正苦于以下问题:C# IndentedStringBuilder类的具体用法?C# IndentedStringBuilder怎么用?C# IndentedStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ConstructModelMapper

 public override string ConstructModelMapper()
 {
     var modelMapper = this.ConstructMapper(SerializedName, null, true, true);
     var builder = new IndentedStringBuilder("  ");
     builder.AppendLine("return {{{0}}};", modelMapper);
     return builder.ToString();
 }
开发者ID:devigned,项目名称:autorest,代码行数:7,代码来源:PageCompositeTypeJsa.cs

示例2: AppendDoesNotAddIndentation

 public void AppendDoesNotAddIndentation(string input)
 {
     IndentedStringBuilder sb = new IndentedStringBuilder();
     var expected = input;
     var result = sb.Indent().Append(input);
     Assert.Equal(expected, result.ToString());
 }
开发者ID:jhancock93,项目名称:autorest,代码行数:7,代码来源:IndentedStringBuilderTests.cs

示例3: AppendWorksWithNull

 public void AppendWorksWithNull()
 {
     IndentedStringBuilder sb = new IndentedStringBuilder();
     var expected = "";
     var result = sb.Indent().Append(null);
     Assert.Equal(expected, result.ToString());
 }
开发者ID:jhancock93,项目名称:autorest,代码行数:7,代码来源:IndentedStringBuilderTests.cs

示例4: CheckNull

 public static string CheckNull(string valueReference, string executionBlock)
 {
     var sb = new IndentedStringBuilder();
     sb.AppendLine("if ({0} != null)", valueReference)
         .AppendLine("{").Indent()
             .AppendLine(executionBlock).Outdent()
         .AppendLine("}");
     return sb.ToString();
 }
开发者ID:jhancock93,项目名称:autorest,代码行数:9,代码来源:ClientModelExtensions.cs

示例5: AppendMultilinePreservesIndentation

        public void AppendMultilinePreservesIndentation()
        {
            IndentedStringBuilder sb = new IndentedStringBuilder();
            var expected = string.Format("start{0}    line2{0}        line31{0}        line32{0}", Environment.NewLine);
            var result = sb
                .AppendLine("start").Indent()
                    .AppendLine("line2").Indent()
                    .AppendLine(string.Format("line31{0}line32", Environment.NewLine));
            Assert.Equal(expected, result.ToString());

            sb = new IndentedStringBuilder();
            expected = string.Format("start{0}    line2{0}        line31{0}        line32{0}", Environment.NewLine);
            result = sb
                .AppendLine("start").Indent()
                    .AppendLine("line2").Indent()
                    .AppendLine(string.Format("line31{0}line32", Environment.NewLine));
            Assert.Equal(expected, result.ToString());
        }
开发者ID:jhancock93,项目名称:autorest,代码行数:18,代码来源:IndentedStringBuilderTests.cs

示例6: ConstructParameterDocumentation

 public static string ConstructParameterDocumentation(string documentation)
 {
     var builder = new IndentedStringBuilder("  ");
     return builder.AppendLine(documentation)
                   .AppendLine(" * ").ToString();
 }
开发者ID:garimakhulbe,项目名称:autorest,代码行数:6,代码来源:MethodTemplateModel.cs

示例7: BuildFlattenParameterMappings

        public virtual string BuildFlattenParameterMappings()
        {
            var builder = new IndentedStringBuilder();
            foreach (var transformation in InputParameterTransformation)
            {
                builder.AppendLine("var {0};",
                        transformation.OutputParameter.Name);

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

                if (transformation.ParameterMappings.Any(m => !string.IsNullOrEmpty(m.OutputParameterProperty)) &&
                    transformation.OutputParameter.Type is CompositeType)
                {
                    builder.AppendLine("{0} = new client.models['{1}']();",
                        transformation.OutputParameter.Name,
                        transformation.OutputParameter.Type.Name);
                }

                foreach (var mapping in transformation.ParameterMappings)
                {
                    builder.AppendLine("{0}{1};",
                        transformation.OutputParameter.Name,
                        mapping);
                }

                builder.Outdent()
                       .AppendLine("}");
            }

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

示例8: ConstructPropertyDocumentation

 public static string ConstructPropertyDocumentation(string propertyDocumentation)
 {
     var builder = new IndentedStringBuilder("  ");
     return builder.AppendLine(propertyDocumentation)
                   .AppendLine(" * ").ToString();
 }
开发者ID:devigned,项目名称:autorest,代码行数:6,代码来源:CompositeTypeJs.cs

示例9: Fields

        public static string Fields(this CompositeType compositeType)
        {
            var indented = new IndentedStringBuilder("    ");
            var properties = compositeType.Properties;

            if (compositeType.BaseModelType != null)
            {
                indented.Append(compositeType.BaseModelType.Fields());
            }

            // If the type is a paged model type, ensure the nextLink field exists
            // Note: Inject the field into a copy of the property list so as to not pollute the original list
            if (    compositeType is ModelTemplateModel
                &&  !String.IsNullOrEmpty((compositeType as ModelTemplateModel).NextLink))
            {
                var nextLinkField = (compositeType as ModelTemplateModel).NextLink;
                foreach (Property p in properties) {
                    p.Name = GoCodeNamer.PascalCaseWithoutChar(p.Name, '.');
                    if (p.Name.Equals(nextLinkField, StringComparison.OrdinalIgnoreCase)) {
                        p.Name = nextLinkField;
                    }
                }
                if (!properties.Any(p => p.Name.Equals(nextLinkField, StringComparison.OrdinalIgnoreCase)))
                {
                    var property = new Property();
                    property.Name = nextLinkField;
                    property.Type = new PrimaryType(KnownPrimaryType.String) { Name = "string" };
                    properties = new List<Property>(properties);
                    properties.Add(property);
                }
            }

            // Emit each property, except for named Enumerated types, as a pointer to the type
            foreach (var property in properties)
            {
                EnumType enumType = property.Type as EnumType;
                if (enumType != null && enumType.IsNamed())
                {
                    indented.AppendFormat("{0} {1} {2}\n",
                                    property.Name,
                                    enumType.Name,
                                    property.JsonTag());

                }
                else if (property.Type is DictionaryType)
                {
                    indented.AppendFormat("{0} *{1} {2}\n", property.Name, (property.Type as MapType).FieldName, property.JsonTag());
                }
                else
                {
                    indented.AppendFormat("{0} *{1} {2}\n", property.Name, property.Type.Name, property.JsonTag());
                }
            }
            
            return indented.ToString();
        }
开发者ID:devigned,项目名称:autorest,代码行数:56,代码来源:Extensions.cs

示例10: DeserializeResponse

        public string DeserializeResponse(IType type, string valueReference = "result", string responseVariable = "parsedResponse")
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var builder = new IndentedStringBuilder("  ");
            builder.AppendLine("var {0} = null;", responseVariable)
                   .AppendLine("try {")
                   .Indent()
                     .AppendLine("{0} = JSON.parse(responseBody);", responseVariable)
                     .AppendLine("{0} = JSON.parse(responseBody);", valueReference);
            var deserializeBody = GetDeserializationString(type, valueReference, responseVariable);
            if (!string.IsNullOrWhiteSpace(deserializeBody))
            {
                builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", responseVariable)
                         .Indent()
                         .AppendLine(deserializeBody)
                       .Outdent()
                       .AppendLine("}");
            }
            builder.Outdent()
                   .AppendLine("} catch (error) {")
                     .Indent()
                     .AppendLine(DeserializationError)
                   .Outdent()
                   .AppendLine("}");

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

示例11: RemoveDuplicateForwardSlashes

 /// <summary>
 /// Generate code to remove duplicated forward slashes from a URL in code
 /// </summary>
 /// <param name="urlVariableName"></param>
 /// <param name="builder">The stringbuilder for url construction</param>
 /// <returns></returns>
 public virtual string RemoveDuplicateForwardSlashes(string urlVariableName, IndentedStringBuilder builder)
 {
     builder.AppendLine("// trim all duplicate forward slashes in the url");
     builder.AppendLine("var regex = /([^:]\\/)\\/+/gi;");
     builder.AppendLine("{0} = {0}.replace(regex, '$1');", urlVariableName);
     return builder.ToString();
 }
开发者ID:garimakhulbe,项目名称:autorest,代码行数:13,代码来源:MethodTemplateModel.cs

示例12: AzureSerializeType

        /// <summary>
        /// Generates Ruby code in form of string for serializing object of given type.
        /// </summary>
        /// <param name="type">Type of object needs to be serialized.</param>
        /// <param name="scope">Current scope.</param>
        /// <param name="valueReference">Reference to object which needs to serialized.</param>
        /// <returns>Generated Ruby code in form of string.</returns>
        public static string AzureSerializeType(
            this IModelType type,
            IChild scope,
            string valueReference)
        {
            var composite = type as CompositeType;
            var sequence = type as SequenceType;
            var dictionary = type as DictionaryType;
            var primary = type as PrimaryType;

            var builder = new IndentedStringBuilder("  ");

            if (primary != null)
            {
                if (primary.KnownPrimaryType == KnownPrimaryType.ByteArray)
                {
                    return builder.AppendLine("{0} = Base64.strict_encode64({0}.pack('c*'))", valueReference).ToString();
                }

                if (primary.KnownPrimaryType == KnownPrimaryType.DateTime)
                {
                    return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%FT%TZ')", valueReference).ToString();
                }

                if (primary.KnownPrimaryType == KnownPrimaryType.DateTimeRfc1123)
                {
                    return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%a, %d %b %Y %H:%M:%S GMT')", valueReference).ToString();
                }

                if (primary.KnownPrimaryType == KnownPrimaryType.UnixTime)
                {
                    return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%s')", valueReference).ToString();
                }
            }
            else if (sequence != null)
            {
                var elementVar = scope.GetUniqueName("element");
                var innerSerialization = sequence.ElementType.AzureSerializeType(scope, elementVar);

                if (!string.IsNullOrEmpty(innerSerialization))
                {
                    return
                        builder
                            .AppendLine("unless {0}.nil?", valueReference)
                                .Indent()
                                    .AppendLine("serialized{0} = []", sequence.Name)
                                    .AppendLine("{0}.each do |{1}|", valueReference, elementVar)
                                    .Indent()
                                        .AppendLine(innerSerialization)
                                        .AppendLine("serialized{0}.push({1})", sequence.Name.ToPascalCase(), elementVar)
                                    .Outdent()
                                    .AppendLine("end")
                                    .AppendLine("{0} = serialized{1}", valueReference, sequence.Name.ToPascalCase())
                                .Outdent()
                            .AppendLine("end")
                            .ToString();
                }
            }
            else if (dictionary != null)
            {
                var valueVar = scope.GetUniqueName("valueElement");
                var innerSerialization = dictionary.ValueType.AzureSerializeType(scope, valueVar);
                if (!string.IsNullOrEmpty(innerSerialization))
                {
                    return builder.AppendLine("unless {0}.nil?", valueReference)
                            .Indent()
                              .AppendLine("{0}.each {{ |key, {1}|", valueReference, valueVar)
                                .Indent()
                                  .AppendLine(innerSerialization)
                                  .AppendLine("{0}[key] = {1}", valueReference, valueVar)
                               .Outdent()
                             .AppendLine("}")
                           .Outdent()
                         .AppendLine("end").ToString();
                }
            }
            else if (composite != null)
            {
                var compositeName = composite.Name;
                if(compositeName == "Resource" || compositeName == "SubResource")
                {
                    compositeName = string.Format(CultureInfo.InvariantCulture, "{0}::{1}", "MsRestAzure", compositeName);
                }
                return builder.AppendLine("unless {0}.nil?", valueReference)
                    .Indent()
                        .AppendLine("{0} = {1}.serialize_object({0})", valueReference, compositeName)
                    .Outdent()
                    .AppendLine("end").ToString();
            }

            return string.Empty;
        }
开发者ID:devigned,项目名称:autorest,代码行数:99,代码来源:AzureClientModelExtensions.cs

示例13: BuildOptionalMappings

 public string BuildOptionalMappings()
 {
     IEnumerable<Property> optionalParameters =
         ((CompositeType)OptionsParameterTemplateModel.Type)
         .Properties.Where(p => p.Name != "customHeaders");
     var builder = new IndentedStringBuilder("  ");
     foreach (var optionalParam in optionalParameters)
     {
         string defaultValue = "undefined";
         if (!string.IsNullOrWhiteSpace(optionalParam.DefaultValue))
         {
             defaultValue = optionalParam.DefaultValue;
         }
         builder.AppendLine("var {0} = ({1} && {1}.{2} !== undefined) ? {1}.{2} : {3};",
             optionalParam.Name, OptionsParameterTemplateModel.Name, optionalParam.Name, defaultValue);
     }
     return builder.ToString();
 }
开发者ID:garimakhulbe,项目名称:autorest,代码行数:18,代码来源:MethodTemplateModel.cs

示例14: TransformPagingGroupedParameter

 protected override void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod, bool filterRequired = false)
 {
     if (this.InputParameterTransformation.IsNullOrEmpty() || nextMethod.InputParameterTransformation.IsNullOrEmpty())
     {
         return;
     }
     var groupedType = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
     var nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
     if (nextGroupType.Name == groupedType.Name)
     {
         return;
     }
     var nextGroupTypeName = _namer.GetTypeName(nextGroupType.Name) + "Inner";
     if (filterRequired && !groupedType.IsRequired)
     {
         return;
     }
     if (!groupedType.IsRequired)
     {
         builder.AppendLine("{0} {1} = null;", nextGroupTypeName, nextGroupType.Name.ToCamelCase());
         builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
         builder.Indent();
         builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
     }
     else
     {
         builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
     }
     foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
     {
         builder.AppendLine("{0}.with{1}({2}.{3}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase(), outParam.Name.ToCamelCase());
     }
     if (!groupedType.IsRequired)
     {
         builder.Outdent().AppendLine(@"}");
     }
 }
开发者ID:jhancock93,项目名称:autorest,代码行数:37,代码来源:AzureFluentMethodTemplateModel.cs

示例15: ConstructImportTS

        public string ConstructImportTS()
        {
            IndentedStringBuilder builder = new IndentedStringBuilder(IndentedStringBuilder.TwoSpaces);
            builder.Append("import { ServiceClientOptions, RequestOptions, ServiceCallback");
            if (Properties.Any(p => p.Name.Equals("credentials", StringComparison.InvariantCultureIgnoreCase)))
            {
                builder.Append(", ServiceClientCredentials");
            }

            builder.Append(" } from 'ms-rest';");
            return builder.ToString();
        }
开发者ID:jhancock93,项目名称:autorest,代码行数:12,代码来源:ServiceClientTemplateModel.cs


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