• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Utilities.IndentedStringBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AppendWorksWithNull

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


示例2: DeserializeProperty

        /// <summary>
        /// Generates code for model deserialization.
        /// </summary>
        /// <param name="variableName">Variable deserialize model from.</param>
        /// <param name="type">The type of the model.</param>
        /// <returns>The code for вуserialization in string format.</returns>
        public override string DeserializeProperty(string variableName, IType type)
        {
            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = type.AzureDeserializeType(this.Scope, variableName);
            return builder.AppendLine(serializationLogic).ToString();
        }
开发者ID:Ranjana1996,项目名称:autorest,代码行数:13,代码来源:AzureModelTemplateModel.cs


示例3: 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:tonytang-microsoft-com,项目名称:autorest,代码行数:7,代码来源:IndentedStringBuilderTests.cs


示例4: GetOperationsRequiredFiles

 public string GetOperationsRequiredFiles()
 {
     var sb = new IndentedStringBuilder();
     this.MethodGroups.ForEach(method => sb.AppendLine("{0}",
         this.GetRequiredFormat(RubyCodeNamer.UnderscoreCase(method) + ".rb")));
     return sb.ToString();
 }
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:7,代码来源:RequirementsTemplateModel.cs


示例5: DeserializePollingResponse

        /// <summary>
        /// Generates Ruby code in form of string for deserializing polling response.
        /// </summary>
        /// <param name="variableName">Variable name which keeps the response.</param>
        /// <param name="type">Type of response.</param>
        /// <returns>Ruby code in form of string for deserializing polling response.</returns>
        public string DeserializePollingResponse(string variableName, IType type)
        {
            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = type.DeserializeType(this.Scope, variableName);
            return builder.AppendLine(serializationLogic).ToString();
        }
开发者ID:Ranjana1996,项目名称:autorest,代码行数:13,代码来源:AzureMethodTemplateModel.cs


示例6: 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:RemcoHulshoff,项目名称:autorest,代码行数:7,代码来源:PageTemplateModel.cs


示例7: BuildUrl

        /// <summary>
        /// Generate code to build the URL from a url expression and method parameters.
        /// </summary>
        /// <param name="inputVariableName">The variable to prepare url from.</param>
        /// <param name="outputVariableName">The variable that will keep the url.</param>
        /// <returns>Code for URL generation.</returns>
        public override string BuildUrl(string inputVariableName, string outputVariableName)
        {
            var builder = new IndentedStringBuilder("  ");

            // Filling path parameters (which are directly in the url body).
            foreach (var pathParameter in ParameterTemplateModels.Where(p => p.Location == ParameterLocation.Path))
            {
                string variableName = pathParameter.Type.ToString(pathParameter.Name);

                string addPathParameterString = String.Format(CultureInfo.InvariantCulture, "{0}['{{{1}}}'] = ERB::Util.url_encode({2})",
                    inputVariableName,
                    pathParameter.SerializedName,
                    variableName);

                if (pathParameter.Extensions.ContainsKey(AzureCodeGenerator.SkipUrlEncodingExtension))
                {
                    addPathParameterString = String.Format(CultureInfo.InvariantCulture, "{0}['{{{1}}}'] = {2}",
                        inputVariableName,
                        pathParameter.SerializedName,
                        variableName);
                }

                builder.AppendLine(addPathParameterString);
            }

            // Adding prefix in case of not absolute url.
            if (!this.IsAbsoluteUrl)
            {
                builder.AppendLine("{0} = URI.join({1}.base_url, {2})", outputVariableName, ClientReference, inputVariableName);
            }
            else
            {
                builder.AppendLine("{0} = URI.parse({1})", outputVariableName, inputVariableName);
            }

            // Filling query parameters (which are directly in the url query part). 
            var queryParametres = ParameterTemplateModels.Where(p => p.Location == ParameterLocation.Query).ToList();

            builder.AppendLine("properties = {}");

            foreach (var param in queryParametres)
            {
                if (param.Extensions.ContainsKey(AzureCodeGenerator.SkipUrlEncodingExtension))
                {
                    builder.AppendLine("properties['{0}'] = {1} unless {1}.nil?", param.SerializedName, param.Name);
                }
                else
                {
                    builder.AppendLine("properties['{0}'] = ERB::Util.url_encode({1}.to_s) unless {1}.nil?", param.SerializedName, param.Name);
                }
            }

            builder.AppendLine("properties.reject!{ |key, value| value.nil? }");
            builder.AppendLine("{0}.query = properties.map{{ |key, value| \"#{{key}}=#{{value}}\" }}.compact.join('&')", outputVariableName);

            builder.AppendLine(@"fail URI::Error unless {0}.to_s =~ /\A#{{URI::regexp}}\z/", outputVariableName);

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


示例8: GetModelsRequiredFiles

        public string GetModelsRequiredFiles()
        {
            var sb = new IndentedStringBuilder();

            this.GetOrderedModels().Where(m => !m.Extensions.ContainsKey(ExternalExtension)).ForEach(model => sb.AppendLine("{0}",
                this.GetRequiredFormat("models/" + RubyCodeNamer.UnderscoreCase(model.Name) + ".rb")));

            this.EnumTypes.ForEach(enumType => sb.AppendLine(this.GetRequiredFormat("models/" + RubyCodeNamer.UnderscoreCase(enumType.Name) + ".rb")));

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


示例9: SerializeProperty

        /// <summary>
        /// Generates code for model serialization.
        /// </summary>
        /// <param name="variableName">Variable serialize model from.</param>
        /// <param name="type">The type of the model.</param>
        /// <param name="isRequired">Is property required.</param>
        /// <param name="defaultNamespace">The namespace.</param>
        /// <returns>The code for serialization in string format.</returns>
        public string SerializeProperty(string variableName, IType type, bool isRequired, string defaultNamespace)
        {
            // TODO: handle if property required via "unless serialized_property.nil?"

            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = type.SerializeType(this.Scope, variableName, defaultNamespace);

            builder.AppendLine(serializationLogic);

            return builder.ToString();
            // return builder.AppendLine("{0} = JSON.generate({0}, quirks_mode: true)", variableName).ToString();
        }
开发者ID:juvchan,项目名称:autorest,代码行数:21,代码来源:ModelTemplateModel.cs


示例10: 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:tonytang-microsoft-com,项目名称:autorest,代码行数:18,代码来源:IndentedStringBuilderTests.cs


示例11: AppendMultilinePreservesIndentation

        public void AppendMultilinePreservesIndentation()
        {
            IndentedStringBuilder sb = new IndentedStringBuilder();
            var expected = "start\r\n    line2\r\n        line31\n        line32\r\n";
            var result = sb
                .AppendLine("start").Indent()
                    .AppendLine("line2").Indent()
                    .AppendLine("line31\nline32");
            Assert.Equal(expected, result.ToString());

            sb = new IndentedStringBuilder();
            expected = "start\r\n    line2\r\n        line31\r\n        line32\r\n";
            result = sb
                .AppendLine("start").Indent()
                    .AppendLine("line2").Indent()
                    .AppendLine("line31\r\nline32");
            Assert.Equal(expected, result.ToString());
        }
开发者ID:juvchan,项目名称:autorest,代码行数:18,代码来源:IndentedStringBuilderTests.cs


示例12: TransformPagingGroupedParameter

 protected override void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod, bool filterRequired = false)
 {
     if (this.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 && !nextGroupType.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:tdjastrzebski,项目名称:autorest,代码行数:37,代码来源:AzureFluentMethodTemplateModel.cs


示例13: AddQueryParametersToUrl

 /// <summary>
 /// Generate code to construct the query string from an array of query parameter strings containing 'key=value'
 /// </summary>
 /// <param name="variableName">The variable reference for the url</param>
 /// <param name="builder">The string builder for url construction</param>
 private static void AddQueryParametersToUrl(string variableName, IndentedStringBuilder builder)
 {
     builder.AppendLine("if (queryParameters.length > 0) {")
         .Indent()
         .AppendLine("{0} += '?' + queryParameters.join('&');", variableName).Outdent()
         .AppendLine("}");
 }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:12,代码来源:MethodTemplateModel.cs


示例14: BuildPathParameters

        /// <summary>
        /// Generate code to replace path parameters in the url template with the appropriate values
        /// </summary>
        /// <param name="variableName">The variable name for the url to be constructed</param>
        /// <param name="builder">The string builder for url construction</param>
        protected virtual void BuildPathParameters(string variableName, IndentedStringBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            foreach (var pathParameter in LogicalParameters.Where(p => p.Location == ParameterLocation.Path))
            {
                var pathReplaceFormat = "{0} = {0}.replace('{{{1}}}', encodeURIComponent({2}));";
                if (pathParameter.SkipUrlEncoding())
                {
                    pathReplaceFormat = "{0} = {0}.replace('{{{1}}}', {2});";
                }
                builder.AppendLine(pathReplaceFormat, variableName, pathParameter.SerializedName,
                    pathParameter.Type.ToString(pathParameter.Name));
            }
        }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:23,代码来源:MethodTemplateModel.cs


示例15: BuildQueryParameterArray

        /// <summary>
        /// Genrate code to build an array of query parameter strings in a variable named 'queryParameters'.  The 
        /// array should contain one string element for each query parameter of the form 'key=value'
        /// </summary>
        /// <param name="builder">The stringbuilder for url construction</param>
        protected virtual void BuildQueryParameterArray(IndentedStringBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.AppendLine("var queryParameters = [];");
            foreach (var queryParameter in LogicalParameters
                .Where(p => p.Location == ParameterLocation.Query))
            {
                var queryAddFormat = "queryParameters.push('{0}=' + encodeURIComponent({1}));";
                if (queryParameter.SkipUrlEncoding())
                {
                    queryAddFormat = "queryParameters.push('{0}=' + {1});";
                }
                if (!queryParameter.IsRequired)
                {
                    builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", queryParameter.Name)
                        .Indent()
                        .AppendLine(queryAddFormat,
                            queryParameter.SerializedName, queryParameter.GetFormattedReferenceValue()).Outdent()
                        .AppendLine("}");
                }
                else
                {
                    builder.AppendLine(queryAddFormat,
                        queryParameter.SerializedName, queryParameter.GetFormattedReferenceValue());
                }
            }
        }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:36,代码来源:MethodTemplateModel.cs


示例16: GetDeserializationString

 public string GetDeserializationString(IType type, string valueReference = "result", string responseVariable = "parsedResponse")
 {
     var builder = new IndentedStringBuilder("  ");
     if (type is CompositeType)
     {
         builder.AppendLine("var resultMapper = new client.models['{0}']().mapper();", type.Name);
     }
     else
     {
         builder.AppendLine("var resultMapper = {{{0}}};", type.ConstructMapper(responseVariable, null, false, false));
     }
     builder.AppendLine("{1} = client.deserialize(resultMapper, {0}, '{1}');", responseVariable, valueReference);
     return builder.ToString();
 }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:14,代码来源:MethodTemplateModel.cs


示例17: RemoveDuplicateForwardSlashes

        /// <summary>
        /// Generate code to remove duplicated forward slashes from a URL in code
        /// </summary>
        /// <param name="urlVariableName"></param>
        /// <returns></returns>
        public virtual string RemoveDuplicateForwardSlashes(string urlVariableName)
        {
            var builder = new IndentedStringBuilder("  ");

            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:RemcoHulshoff,项目名称:autorest,代码行数:14,代码来源:MethodTemplateModel.cs


示例18: 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:RemcoHulshoff,项目名称:autorest,代码行数:31,代码来源:MethodTemplateModel.cs


示例19: 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:tonytang-microsoft-com,项目名称:autorest,代码行数:9,代码来源:ClientModelExtensions.cs


示例20: AddIndividualResponseHeader

        public virtual string AddIndividualResponseHeader(HttpStatusCode? code)
        {
            IType headersType = null;

            if (HasResponseHeader)
            {
                if (code != null)
                {
                    headersType = this.ReturnType.Headers;
                }
                else
                {
                    headersType = this.Responses[code.Value].Headers;
                }
            }

            var builder = new IndentedStringBuilder("    ");
            if (headersType == null)
            {
                if (code == null)
                {
                    builder.AppendLine("header_dict = {}");
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                builder.AppendLine("header_dict = {").Indent();
                AddHeaderDictionary(builder, (CompositeType)headersType);
                builder.Outdent().AppendLine("}");
            }
            return builder.ToString();
        }
开发者ID:CamSoper,项目名称:autorest,代码行数:36,代码来源:MethodTemplateModel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SPOT.Bitmap类代码示例发布时间:2022-05-26
下一篇:
C# ClientModel.ServiceClient类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap