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


C# IndentedStringBuilder.ToString方法代码示例

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


在下文中一共展示了IndentedStringBuilder.ToString方法的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:RemcoHulshoff,项目名称:autorest,代码行数:7,代码来源:PageTemplateModel.cs

示例2: 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

示例3: 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>
        /// <returns>The code for serialization in string format.</returns>
        public override string SerializeProperty(string variableName, IType type)
        {
            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = type.AzureSerializeType(this.Scope, variableName);
            builder.AppendLine(serializationLogic);

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

示例4: 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

示例5: BuildInputMappings

 /// <summary>
 /// Generates input mapping code block.
 /// </summary>
 /// <returns></returns>
 public virtual string BuildInputMappings()
 {
     var builder = new IndentedStringBuilder("  ");
     if (InputParameterTransformation.Count > 0)
     {
         if (AreWeFlatteningParameters())
         {
             return BuildFlattenParameterMappings();
         }
         else
         {
             return BuildGroupedParameterMappings();
         }
     }
     return builder.ToString();
 }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:20,代码来源:MethodTemplateModel.cs

示例6: BuildGroupedParameterMappings

        public virtual string BuildGroupedParameterMappings()
        {
            var builder = new IndentedStringBuilder("  ");
            if (InputParameterTransformation.Count > 0)
            {
                // Declare all the output paramaters outside the try block
                foreach (var transformation in InputParameterTransformation)
                {
                    builder.AppendLine("var {0};", transformation.OutputParameter.Name);
                }
                builder.AppendLine("try {").Indent();
                foreach (var transformation in InputParameterTransformation)
                {
                    builder.AppendLine("if ({0})", BuildNullCheckExpression(transformation))
                           .AppendLine("{").Indent();
                    var outputParameter = transformation.OutputParameter;
                    bool noCompositeTypeInitialized = true;
                    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);
                        noCompositeTypeInitialized = false;
                    }

                    foreach (var mapping in transformation.ParameterMappings)
                    {
                        builder.AppendLine("{0}{1};",
                            transformation.OutputParameter.Name,
                            mapping);
                        if (noCompositeTypeInitialized)
                        {
                            // If composite type is initialized based on the above logic then it shouuld not be validated.
                            builder.AppendLine(outputParameter.Type.ValidateType(Scope, outputParameter.Name, outputParameter.IsRequired));
                        }
                    }

                    builder.Outdent()
                           .AppendLine("}");
                }
                builder.Outdent()
                       .AppendLine("} catch (error) {")
                         .Indent()
                         .AppendLine("return callback(error);")
                       .Outdent()
                       .AppendLine("}");
            }
            return builder.ToString();
        }
开发者ID:RemcoHulshoff,项目名称:autorest,代码行数:50,代码来源:MethodTemplateModel.cs

示例7: 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

示例8: BuildHeaders

        /// <summary>
        /// Generate code to build the headers from method parameters
        /// </summary>
        /// <param name="variableName">The variable to store the headers in.</param>
        /// <returns></returns>
        public virtual string BuildHeaders(string variableName)
        {
            var builder = new IndentedStringBuilder("    ");

            foreach (var headerParameter in this.LogicalParameters.Where(p => p.Location == ParameterLocation.Header))
            {
                if (headerParameter.IsRequired)
                {
                    builder.AppendLine("{0}['{1}'] = {2}",
                            variableName,
                            headerParameter.SerializedName,
                            BuildSerializeDataCall(headerParameter, "header"));
                }
                else
                {
                    builder.AppendLine("if {0} is not None:", headerParameter.Name)
                        .Indent()
                        .AppendLine("{0}['{1}'] = {2}", 
                            variableName,
                            headerParameter.SerializedName,
                            BuildSerializeDataCall(headerParameter, "header"))
                        .Outdent();
                }
            }

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

示例9: ValidateType

        /// <summary>
        /// Generate code to perform required validation on a type
        /// </summary>
        /// <param name="type">The type to validate</param>
        /// <param name="scope">A scope provider for generating variable names as necessary</param>
        /// <param name="valueReference">A reference to the value being validated</param>
        /// <returns>The code to validate the reference of the given type</returns>
        public static string ValidateType(this IType type, IScopeProvider scope, string valueReference)
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            CompositeType model = type as CompositeType;
            SequenceType sequence = type as SequenceType;
            DictionaryType dictionary = type as DictionaryType;
            if (model != null && model.ShouldValidateChain())
            {
                return CheckNull(valueReference, string.Format(CultureInfo.InvariantCulture, 
                    "{0}.Validate();", valueReference));
            }
            if (sequence != null && sequence.ShouldValidateChain())
            {
                var elementVar = scope.GetVariableName("element");
                var innerValidation = sequence.ElementType.ValidateType(scope, elementVar);
                if (!string.IsNullOrEmpty(innerValidation))
                {
                    var sb = new IndentedStringBuilder();
                    sb.AppendLine("foreach (var {0} in {1})", elementVar, valueReference)
                        .AppendLine("{").Indent()
                            .AppendLine(innerValidation).Outdent()
                        .AppendLine("}");
                    return CheckNull(valueReference, sb.ToString());
                }
            }
            else if (dictionary != null && dictionary.ShouldValidateChain())
            {
                var valueVar = scope.GetVariableName("valueElement");
                var innerValidation = dictionary.ValueType.ValidateType(scope, valueVar);
                if (!string.IsNullOrEmpty(innerValidation))
                {
                    var sb = new IndentedStringBuilder();
                    sb.AppendLine("if ({0} != null)", valueReference)
                        .AppendLine("{").Indent()
                            .AppendLine("foreach (var {0} in {1}.Values)",valueVar,valueReference)
                            .AppendLine("{").Indent()
                                .AppendLine(innerValidation).Outdent()
                            .AppendLine("}").Outdent()
                        .AppendLine("}");

                    return CheckNull(valueReference, sb.ToString());
                }
            }

            return null;
        }
开发者ID:tonytang-microsoft-com,项目名称:autorest,代码行数:57,代码来源:ClientModelExtensions.cs

示例10: 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

示例11: 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

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

示例13: GetModelsRequiredFiles

        /// <summary>
        /// Returns the list of model files for 'autoloading' them.
        /// </summary>
        /// <returns>Model files list in form of string.</returns>
        public string GetModelsRequiredFiles()
        {
            var sb = new IndentedStringBuilder();

            this.GetOrderedModels()
                .Where(m => !ExcludeModel(m))
                .ForEach(model => sb.AppendLine(this.GetAutoloadFormat(model.Name, "models/" + RubyCodeNamer.UnderscoreCase(model.Name) + this.implementationFileExtension)));

            this.EnumTypes.ForEach(enumType => sb.AppendLine(this.GetAutoloadFormat(enumType.Name, "models/" + RubyCodeNamer.UnderscoreCase(enumType.Name) + this.implementationFileExtension)));

            return sb.ToString();
        }
开发者ID:maxkeller,项目名称:autorest,代码行数:16,代码来源:RequirementsTemplateModel.cs

示例14: GetOperationsRequiredFiles

        /// <summary>
        /// Returns a list of methods groups for 'autoloading' them.
        /// </summary>
        /// <returns>Method groups list in form of string.</returns>
        public string GetOperationsRequiredFiles()
        {
            var sb = new IndentedStringBuilder();

            this.MethodGroups.ForEach(method => sb.AppendLine("{0}",
                this.GetAutoloadFormat(method, RubyCodeNamer.UnderscoreCase(method) + this.implementationFileExtension)));

            return sb.ToString();
        }
开发者ID:maxkeller,项目名称:autorest,代码行数:13,代码来源:RequirementsTemplateModel.cs

示例15: GetDeserializationString

        /// <summary>
        /// Creates deserialization logic for the given <paramref name="type"/>.
        /// </summary>
        /// <param name="type">Type for which deserialization logic being constructed.</param>
        /// <param name="valueReference">Reference variable name.</param>
        /// <param name="responseVariable">Response variable name.</param>
        /// <returns>Deserialization logic for the given <paramref name="type"/> as string.</returns>
        /// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
        public string GetDeserializationString(IType type, string valueReference = "result", string responseVariable = "parsed_response")
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var builder = new IndentedStringBuilder("  ");
            if (type is CompositeType)
            {
                builder.AppendLine("result_mapper = {0}.mapper()", type.Name);
            }
            else
            {
                builder.AppendLine("result_mapper = {{{0}}}", type.ConstructMapper(responseVariable, null, false));
            }
            if (Group == null)
            {
                builder.AppendLine("{1} = self.deserialize(result_mapper, {0}, '{1}')", responseVariable, valueReference);
            }
            else
            {
                builder.AppendLine("{1} = @client.deserialize(result_mapper, {0}, '{1}')", responseVariable, valueReference);
            }
             
            return builder.ToString();
        }
开发者ID:xingwu1,项目名称:autorest,代码行数:35,代码来源:MethodTemplateModel.cs


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