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


C# IndentedStringBuilder.Outdent方法代码示例

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


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

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

示例2: DeserializeType

        /// <summary>
        /// Generate code to perform deserialization on a parameter or property
        /// </summary>
        /// <param name="type">The type to deserialize</param>
        /// <param name="scope">A scope provider for generating variable names as necessary</param>
        /// <param name="objectReference">A reference to the object that will be assigned the deserialized value</param>
        /// <param name="valueReference">A reference to the value being deserialized</param>
        /// <param name="modelReference">A reference to the models</param>
        /// <returns>The code to deserialize the given type</returns>
        public static string DeserializeType(this IType type, IScopeProvider scope, string objectReference, string valueReference, string modelReference = "self._models")
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            EnumType enumType = type as EnumType;
            CompositeType composite = type as CompositeType;
            SequenceType sequence = type as SequenceType;
            DictionaryType dictionary = type as DictionaryType;
            PrimaryType primary = type as PrimaryType;
            var builder = new IndentedStringBuilder("  ");
            string baseProperty = valueReference.GetBasePropertyFromUnflattenedProperty();
            if (baseProperty != null)
            {
                builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", baseProperty).Indent();
            }
            if (enumType != null)
            {
                builder = ProcessBasicType(objectReference, valueReference, builder);
            }
            else if (primary != null)
            {
                if (primary == PrimaryType.ByteArray)
                {
                    builder.AppendLine("if ({0}) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = new Buffer({0}, 'base64');", valueReference, objectReference)
                           .Outdent().AppendLine("}")
                           .AppendLine("else if ({0} !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = {0};", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}");
                }
                else if (primary == PrimaryType.DateTime || primary == PrimaryType.Date || primary == PrimaryType.DateTimeRfc1123)
                {
                    builder.AppendLine("if ({0}) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = new Date({0});", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}")
                           .AppendLine("else if ({0} !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = {0};", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}");
                }
                else if (primary == PrimaryType.TimeSpan)
                {
                    builder.AppendLine("if ({0}) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = moment.duration({0});", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}")
                           .AppendLine("else if ({0} !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = {0};", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}");
                }
                else
                {
                    builder.AppendLine("if ({0} !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine("{1} = {0};", valueReference, objectReference)
                           .Outdent()
                           .AppendLine("}");
                }
            }
            else if (composite != null && composite.Properties.Any())
            {
                builder = composite.ProcessCompositeType(objectReference, valueReference, modelReference, builder, "DeserializeType");
            }
            else if (sequence != null)
            {
                builder = sequence.ProcessSequenceType(scope, objectReference, valueReference, modelReference, builder, "DeserializeType");
            }
            else if (dictionary != null)
            {
                builder = dictionary.ProcessDictionaryType(scope, objectReference, valueReference, modelReference, builder, "DeserializeType");
            }

            if (baseProperty != null)
            {
                builder.Outdent().AppendLine("}");
            }

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

示例3: BuildUrl

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

            foreach (var pathParameter in this.LogicalParameterTemplateModels.Where(p => p.Location == ParameterLocation.Path))
            {
                string replaceString = "{0} = {0}.Replace(\"{{{1}}}\", Uri.EscapeDataString({2}));";
                if (pathParameter.SkipUrlEncoding())
                {
                    replaceString = "{0} = {0}.Replace(\"{{{1}}}\", {2});";
                }

                builder.AppendLine(replaceString,
                    variableName,
                    pathParameter.SerializedName,
                    pathParameter.Type.ToString(ClientReference, pathParameter.Name));
            }
            if (this.LogicalParameterTemplateModels.Any(p => p.Location == ParameterLocation.Query))
            {
                builder.AppendLine("List<string> _queryParameters = new List<string>();");
                foreach (var queryParameter in this.LogicalParameterTemplateModels.Where(p => p.Location == ParameterLocation.Query))
                {
                    var replaceString = "_queryParameters.Add(string.Format(\"{0}={{0}}\", Uri.EscapeDataString({1})));";
                    if (queryParameter.CanBeNull())
                    {
                        builder.AppendLine("if ({0} != null)", queryParameter.Name)
                            .AppendLine("{").Indent();
                    }

                    if(queryParameter.SkipUrlEncoding())
                    {
                        replaceString = "_queryParameters.Add(string.Format(\"{0}={{0}}\", {1}));";
                    }

                    builder.AppendLine(replaceString,
                            queryParameter.SerializedName, queryParameter.GetFormattedReferenceValue(ClientReference));

                    if (queryParameter.CanBeNull())
                    {
                        builder.Outdent()
                            .AppendLine("}");
                    }
                }

                builder.AppendLine("if (_queryParameters.Count > 0)")
                    .AppendLine("{").Indent();
                if (this.Extensions.ContainsKey("nextLinkMethod") && (bool)this.Extensions["nextLinkMethod"])
                {
                    builder.AppendLine("{0} += ({0}.Contains(\"?\") ? \"&\" : \"?\") + string.Join(\"&\", _queryParameters);", variableName);
                }
                else
                {
                    builder.AppendLine("{0} += \"?\" + string.Join(\"&\", _queryParameters);", variableName);
                }

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

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

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

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

示例6: 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))
                       .AppendLine("{").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:RemcoHulshoff,项目名称:autorest,代码行数:32,代码来源:MethodTemplateModel.cs

示例7: 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.GetUniqueName("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("}");
            if (isRequired)
            {
                var escapedValueReference = valueReference.EscapeSingleQuotes();
                builder.Outdent().AppendLine("} else {")
                    .Indent()
                        .AppendLine("throw new Error('{0} cannot be null or undefined.');", escapedValueReference)
                    .Outdent()
                    .AppendLine("}");
            }
            else
            {
                builder.Outdent().AppendLine("}");
            }
            
            return builder.ToString();
        }
开发者ID:jkonecki,项目名称:autorest,代码行数:34,代码来源:ClientModelExtensions.cs

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

示例9: ValidateType

        /// <summary>
        /// Generate code to perform validation on a parameter or property
        /// </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>
        /// <param name="modelReference">A reference to the models array</param>
        /// <returns>The code to validate the reference of the given type</returns>
        public static string ValidateType(this IType type, IScopeProvider scope, string valueReference, string modelReference = "client._models")
        {
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            CompositeType composite = type as CompositeType;
            SequenceType sequence = type as SequenceType;
            DictionaryType dictionary = type as DictionaryType;
            PrimaryType primary = type as PrimaryType;
            EnumType enumType = type as EnumType;
            var builder = new IndentedStringBuilder("  ");
            var escapedValueReference = valueReference.EscapeSingleQuotes();
            if(primary != null)
            {
                if (primary == PrimaryType.String ||
                    primary == PrimaryType.Boolean ||
                    primary == PrimaryType.Double ||
                    primary == PrimaryType.Int ||
                    primary == PrimaryType.Long)
                {
                    return builder.AppendLine("if ({0} !== null && {0} !== undefined && typeof {0} !== '{1}') {{", valueReference, primary.Name.ToLower(CultureInfo.InvariantCulture))
                            .Indent()
                                .AppendLine("throw new Error('{0} must be of type {1}.');", escapedValueReference, primary.Name.ToLower(CultureInfo.InvariantCulture))
                            .Outdent()
                          .AppendLine("}").ToString();
                }
                else if (primary == PrimaryType.ByteArray)
                {
                    return builder.AppendLine("if ({0} !== null && {0} !== undefined && !Buffer.isBuffer({0})) {{", valueReference)
                            .Indent()
                                .AppendLine("throw new Error('{0} must be of type {1}.');", escapedValueReference, primary.Name.ToLower(CultureInfo.InvariantCulture))
                            .Outdent()
                          .AppendLine("}").ToString();
                }
                else if (primary == PrimaryType.DateTime || primary == PrimaryType.Date)
                {
                    return builder.AppendLine("if ({0} !== null && {0} !== undefined && ", valueReference)
                    .Indent()
                    .Indent()
                        .AppendLine("!({0} instanceof Date || ", valueReference)
                            .Indent()
                                .AppendLine("(typeof {0} === 'string' && !isNaN(Date.parse({0}))))) {{", valueReference)
                           .Outdent()
                           .Outdent()
                    .AppendLine("throw new Error('{0} must be of type {1}.');", escapedValueReference, primary.Name.ToLower(CultureInfo.InvariantCulture))
                           .Outdent()
                           .AppendLine("}").ToString();
                }
                else if (primary == PrimaryType.Object)
                {
                    return builder.ToString();
                }
                else
                {
                    throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, 
                        "'{0}' not implemented", valueReference));
                }
            }
            else if (enumType != null && enumType.Values.Any()) {
                var allowedValues = scope.GetVariableName("allowedValues");
                return builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", 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("}").ToString();
            }
            else if (composite != null && composite.Properties.Any())
            {
                builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", 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)
//.........这里部分代码省略.........
开发者ID:juvchan,项目名称:autorest,代码行数:101,代码来源:ClientModelExtensions.cs

示例10: BuildInputMappings

        /// <summary>
        /// Generates input mapping code block.
        /// </summary>
        /// <returns></returns>
        public virtual string BuildInputMappings(bool filterRequired = false)
        {
            var builder = new IndentedStringBuilder();
            foreach (var transformation in InputParameterTransformation)
            {
                var nullCheck = BuildNullCheckExpression(transformation);
                bool conditionalAssignment = !string.IsNullOrEmpty(nullCheck) && !transformation.OutputParameter.IsRequired && !filterRequired;
                if (conditionalAssignment)
                {
                    builder.AppendLine("{0} {1} = null;",
                            ((ParameterModel) transformation.OutputParameter).ClientType.ParameterVariant,
                            transformation.OutputParameter.Name);
                    builder.AppendLine("if ({0}) {{", nullCheck).Indent();
                }

                if (transformation.ParameterMappings.Any(m => !string.IsNullOrEmpty(m.OutputParameterProperty)) &&
                    transformation.OutputParameter.Type is CompositeType)
                {
                    builder.AppendLine("{0}{1} = new {2}();",
                        !conditionalAssignment ? ((ParameterModel)transformation.OutputParameter).ClientType.ParameterVariant + " " : "",
                        transformation.OutputParameter.Name,
                        transformation.OutputParameter.Type.Name);
                }

                foreach (var mapping in transformation.ParameterMappings)
                {
                    if (filterRequired && !mapping.InputParameter.IsRequired)
                    {
                        builder.AppendLine("{0}{1}{2};",
                            !conditionalAssignment && !(transformation.OutputParameter.Type is CompositeType) ?
                                ((ParameterModel)transformation.OutputParameter).WireType + " " : "",
                            ((ParameterModel)transformation.OutputParameter).WireName,
                            " = " + ((ParameterModel)transformation.OutputParameter).WireType.DefaultValue(this));
                    }
                    else
                    {
                        builder.AppendLine("{0}{1}{2};",
                            !conditionalAssignment && !(transformation.OutputParameter.Type is CompositeType) ?
                                ((ParameterModel)transformation.OutputParameter).ClientType.ParameterVariant + " " : "",
                            transformation.OutputParameter.Name,
                            GetMapping(mapping));
                    }
                }

                if (conditionalAssignment)
                {
                    builder.Outdent()
                       .AppendLine("}");
                }
            }

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

示例11: GetDeserializationString

        public string GetDeserializationString(IType type, string valueReference = "result", string responseVariable = "parsedResponse")
        {
            CompositeType composite = type as CompositeType;
            SequenceType sequence = type as SequenceType;
            DictionaryType dictionary = type as DictionaryType;
            PrimaryType primary = type as PrimaryType;
            EnumType enumType = type as EnumType;
            var builder = new IndentedStringBuilder("  ");
            if (primary != null)
            {
                if (primary == PrimaryType.DateTime ||
                    primary == PrimaryType.Date || 
                    primary == PrimaryType.DateTimeRfc1123)
                {
                    builder.AppendLine("{0} = new Date({0});", valueReference);
                }
                else if (primary == PrimaryType.ByteArray)
                {
                    builder.AppendLine("{0} = new Buffer({0}, 'base64');", valueReference);
                }
                else if (primary == PrimaryType.TimeSpan)
                {
                    builder.AppendLine("{0} = moment.duration({0});", valueReference);
                }
            }
            else if (IsSpecialProcessingRequired(sequence))
            {
                builder.AppendLine("for (var i = 0; i < {0}.length; i++) {{", valueReference)
                         .Indent();
                    
                // Loop through the sequence if each property is Date, DateTime or ByteArray 
                // as they need special treatment for deserialization
                if (sequence.ElementType is PrimaryType)
                {
                    builder.AppendLine("if ({0}[i] !== null && {0}[i] !== undefined) {{", valueReference)
                             .Indent();
                    if (sequence.ElementType == PrimaryType.DateTime ||
                       sequence.ElementType == PrimaryType.Date || 
                        sequence.ElementType == PrimaryType.DateTimeRfc1123)
                    {
                        builder.AppendLine("{0}[i] = new Date({0}[i]);", valueReference);
                    }
                    else if (sequence.ElementType == PrimaryType.ByteArray)
                    {
                        builder.AppendLine("{0}[i] = new Buffer({0}[i], 'base64');", valueReference);
                    }
                    else if (sequence.ElementType == PrimaryType.TimeSpan)
                    {
                        builder.AppendLine("{0}[i] = moment.duration({0}[i]);", valueReference);
                    }
                }
                else if (sequence.ElementType is CompositeType)
                {
                    builder.AppendLine("if ({0}[i] !== null && {0}[i] !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine(GetDeserializationString(sequence.ElementType,
                                string.Format(CultureInfo.InvariantCulture, "{0}[i]", valueReference),
                                string.Format(CultureInfo.InvariantCulture, "{0}[i]", responseVariable)));
                }

                builder.Outdent()
                        .AppendLine("}")
                        .Outdent()
                    .AppendLine("}");
            }
            else if (IsSpecialProcessingRequired(dictionary))
            {
                builder.AppendLine("for (var property in {0}) {{", valueReference)
                    .Indent();
                if (dictionary.ValueType is PrimaryType)
                {
                    builder.AppendLine("if ({0}[property] !== null && {0}[property] !== undefined) {{", valueReference)
                             .Indent();
                    if (dictionary.ValueType == PrimaryType.DateTime || 
                        dictionary.ValueType == PrimaryType.Date || 
                        dictionary.ValueType == PrimaryType.DateTimeRfc1123)
                    {
                        builder.AppendLine("{0}[property] = new Date({0}[property]);", valueReference);
                    }
                    else if (dictionary.ValueType == PrimaryType.ByteArray)
                    {
                        builder.AppendLine("{0}[property] = new Buffer({0}[property], 'base64');", valueReference);
                    }
                    else if (dictionary.ValueType == PrimaryType.TimeSpan)
                    {
                        builder.AppendLine("{0}[property] = moment.duration({0}[property]);", valueReference);
                    }
                }
                else if (dictionary.ValueType is CompositeType)
                {
                    builder.AppendLine("if ({0}[property] !== null && {0}[property] !== undefined) {{", valueReference)
                             .Indent()
                             .AppendLine(GetDeserializationString(dictionary.ValueType,
                                string.Format(CultureInfo.InvariantCulture, "{0}[property]", valueReference),
                                string.Format(CultureInfo.InvariantCulture, "{0}[property]", responseVariable)));
                }
                builder.Outdent()
                        .AppendLine("}")
                        .Outdent()
                    .AppendLine("}");
//.........这里部分代码省略.........
开发者ID:BretJohnson,项目名称:autorest,代码行数:101,代码来源:MethodTemplateModel.cs

示例12: TransformPagingGroupedParameter

 private void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod)
 {
     if (this.InputParameterTransformation.IsNullOrEmpty())
     {
         return;
     }
     var groupedType = this.InputParameterTransformation.FirstOrDefault().ParameterMappings[0].InputParameter;
     var nextGroupType = nextMethod.InputParameterTransformation.FirstOrDefault().ParameterMappings[0].InputParameter;
     if (nextGroupType.Name == groupedType.Name)
     {
         return;
     }
     if (!groupedType.IsRequired)
     {
         builder.AppendLine("{0} {1} = null;", nextGroupType.Name.ToPascalCase(), nextGroupType.Name.ToCamelCase());
         builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
         builder.Indent();
         builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
     }
     else
     { 
         builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
     }
     foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
     {
         builder.AppendLine("{0}.set{1}({2}.get{1}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase());
     }
     if (!groupedType.IsRequired)
     {
         builder.Outdent().AppendLine(@"}");
     }
 }
开发者ID:JamesTryand,项目名称:autorest,代码行数:32,代码来源:AzureMethodTemplateModel.cs

示例13: BuildInputMappings

        /// <summary>
        /// Generates input mapping code block.
        /// </summary>
        /// <returns></returns>
        public virtual string BuildInputMappings()
        {
            var builder = new IndentedStringBuilder();
            foreach (var transformation in InputParameterTransformation)
            {
                var compositeOutputParameter = transformation.OutputParameter.Type as CompositeType;
                if (transformation.OutputParameter.IsRequired && compositeOutputParameter != null)
                {
                    builder.AppendLine("{0} {1} = new {0}();",
                        transformation.OutputParameter.Type.Name,
                        transformation.OutputParameter.Name);
                }
                else
                {
                    builder.AppendLine("{0} {1} = default({0});",
                        transformation.OutputParameter.Type.Name,
                        transformation.OutputParameter.Name);
                }
                var nullCheck = BuildNullCheckExpression(transformation);
                if (!string.IsNullOrEmpty(nullCheck))
                {
                    builder.AppendLine("if ({0})", nullCheck)
                       .AppendLine("{").Indent();
                }
                
                if (transformation.ParameterMappings.Any(m => !string.IsNullOrEmpty(m.OutputParameterProperty)) &&
                    compositeOutputParameter != null && !transformation.OutputParameter.IsRequired)
                {
                    builder.AppendLine("{0} = new {1}();",
                        transformation.OutputParameter.Name,
                        transformation.OutputParameter.Type.Name);
                }

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

                if (!string.IsNullOrEmpty(nullCheck))
                {
                    builder.Outdent()
                       .AppendLine("}");
                }
            }

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

示例14: ProcessCompositeType

        private static IndentedStringBuilder ProcessCompositeType(this CompositeType composite, string objectReference,
            string valueReference, string modelReference, IndentedStringBuilder builder, string processType)
        {
            builder.AppendLine("if ({0}) {{", valueReference).Indent();
            string discriminator = "{3} = new {2}.discriminators[{0}['{1}']]({0});";
            string objectCreation = "{3} = new {2}['{1}']({0});";

            if (processType == "DeserializeType")
            {
                discriminator = "{3} = new {2}.discriminators[{0}['{1}']]().deserialize({0});";
                objectCreation = "{3} = new {2}['{1}']().deserialize({0});";
            }

            if (!string.IsNullOrEmpty(composite.PolymorphicDiscriminator))
            {
                builder.AppendLine(discriminator, valueReference, composite.PolymorphicDiscriminator, modelReference, objectReference);
            }
            else
            {
                builder.AppendLine(objectCreation, valueReference, composite.Name, modelReference, objectReference);
            }
            builder.Outdent().AppendLine("}");

            return builder;
        }
开发者ID:maxkeller,项目名称:autorest,代码行数:25,代码来源:ClientModelExtensions.cs

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


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