本文整理汇总了C#中AutoRest.Core.Utilities.IndentedStringBuilder类的典型用法代码示例。如果您正苦于以下问题:C# IndentedStringBuilder类的具体用法?C# IndentedStringBuilder怎么用?C# IndentedStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndentedStringBuilder类属于AutoRest.Core.Utilities命名空间,在下文中一共展示了IndentedStringBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: AppendConstraintValidations
private static void AppendConstraintValidations(string valueReference, Dictionary<Constraint, string> constraints, IndentedStringBuilder sb, KnownFormat format)
{
foreach (var constraint in constraints.Keys)
{
string constraintCheck;
string constraintValue = (format == [email protected]) ?$"'{constraints[constraint]}'" : constraints[constraint];
switch (constraint)
{
case Constraint.ExclusiveMaximum:
constraintCheck = $"{valueReference} >= {constraintValue}";
break;
case Constraint.ExclusiveMinimum:
constraintCheck = $"{valueReference} <= {constraintValue}";
break;
case Constraint.InclusiveMaximum:
constraintCheck = $"{valueReference} > {constraintValue}";
break;
case Constraint.InclusiveMinimum:
constraintCheck = $"{valueReference} < {constraintValue}";
break;
case Constraint.MaxItems:
constraintCheck = $"{valueReference}.Count > {constraintValue}";
break;
case Constraint.MaxLength:
constraintCheck = $"{valueReference}.Length > {constraintValue}";
break;
case Constraint.MinItems:
constraintCheck = $"{valueReference}.Count < {constraintValue}";
break;
case Constraint.MinLength:
constraintCheck = $"{valueReference}.Length < {constraintValue}";
break;
case Constraint.MultipleOf:
constraintCheck = $"{valueReference} % {constraintValue} != 0";
break;
case Constraint.Pattern:
constraintValue = $"\"{constraintValue.Replace("\\", "\\\\")}\"";
constraintCheck = $"!System.Text.RegularExpressions.Regex.IsMatch({valueReference}, {constraintValue})";
break;
case Constraint.UniqueItems:
if ("true".EqualsIgnoreCase(constraints[constraint]))
{
constraintCheck = $"{valueReference}.Count != {valueReference}.Distinct().Count()";
}
else
{
constraintCheck = null;
}
break;
default:
throw new NotSupportedException("Constraint '" + constraint + "' is not supported.");
}
if (constraintCheck != null)
{
if (constraint != Constraint.UniqueItems)
{
sb.AppendLine("if ({0})", constraintCheck)
.AppendLine("{").Indent()
.AppendLine("throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.{0}, \"{1}\", {2});",
constraint, valueReference.Replace("this.", ""), constraintValue).Outdent()
.AppendLine("}");
}
else
{
sb.AppendLine("if ({0})", constraintCheck)
.AppendLine("{").Indent()
.AppendLine("throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.{0}, \"{1}\");",
constraint, valueReference.Replace("this.", "")).Outdent()
.AppendLine("}");
}
}
}
}
开发者ID:DeepakRajendranMsft,项目名称:autorest,代码行数:73,代码来源:ClientModelExtensions.cs
示例17: 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>
/// <param name="constraints">Constraints</param>
/// <returns>The code to validate the reference of the given type</returns>
public static string ValidateType(this IModelType type, IChild scope, string valueReference,
Dictionary<Constraint, string> constraints)
{
if (scope == null)
{
throw new ArgumentNullException("scope");
}
var model = type as CompositeTypeCs;
var sequence = type as SequenceTypeCs;
var dictionary = type as DictionaryTypeCs;
var sb = new IndentedStringBuilder();
if (model != null && model.ShouldValidateChain())
{
sb.AppendLine("{0}.Validate();", valueReference);
}
if (constraints != null && constraints.Any())
{
AppendConstraintValidations(valueReference, constraints, sb, (type as PrimaryType)?.KnownFormat ?? KnownFormat.none);
}
if (sequence != null && sequence.ShouldValidateChain())
{
var elementVar = scope.GetUniqueName("element");
var innerValidation = sequence.ElementType.ValidateType(scope, elementVar, null);
if (!string.IsNullOrEmpty(innerValidation))
{
sb.AppendLine("foreach (var {0} in {1})", elementVar, valueReference)
.AppendLine("{").Indent()
.AppendLine(innerValidation).Outdent()
.AppendLine("}");
}
}
else if (dictionary != null && dictionary.ShouldValidateChain())
{
var valueVar = scope.GetUniqueName("valueElement");
var innerValidation = dictionary.ValueType.ValidateType(scope, valueVar, null);
if (!string.IsNullOrEmpty(innerValidation))
{
sb.AppendLine("foreach (var {0} in {1}.Values)", valueVar, valueReference)
.AppendLine("{").Indent()
.AppendLine(innerValidation).Outdent()
.AppendLine("}").Outdent();
}
}
if (sb.ToString().Trim().Length > 0)
{
if (type.IsValueType())
{
return sb.ToString();
}
else
{
return CheckNull(valueReference, sb.ToString());
}
}
return null;
}
开发者ID:DeepakRajendranMsft,项目名称:autorest,代码行数:71,代码来源:ClientModelExtensions.cs
示例18: ConstructTSItemTypeName
public string ConstructTSItemTypeName()
{
var builder = new IndentedStringBuilder(" ");
builder.AppendFormat("<{0}>", ItemType.Name);
return builder.ToString();
}
开发者ID:haocs,项目名称:autorest,代码行数:6,代码来源:PageTemplateModel.cs
示例19: 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)
{
if (transformation.OutputParameter.Type is CompositeType &&
transformation.OutputParameter.IsRequired)
{
builder.AppendLine("var {0} = new client.models['{1}']();",
transformation.OutputParameter.Name,
transformation.OutputParameter.Type.Name);
}
else
{
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)
{
//required outputParameter is initialized at the time of declaration
if (!transformation.OutputParameter.IsRequired)
{
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 should 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:garimakhulbe,项目名称:autorest,代码行数:66,代码来源:MethodTemplateModel.cs
示例20: AzureDeserializeType
/// <summary>
/// Generates Ruby code in form of string for deserializing object of given type.
/// </summary>
/// <param name="type">Type of object needs to be deserialized.</param>
/// <param name="scope">Current scope.</param>
/// <param name="valueReference">Reference to object which needs to be deserialized.</param>
/// <returns>Generated Ruby code in form of string.</returns>
public static string AzureDeserializeType(
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 enumType = type as EnumTypeRb;
var builder = new IndentedStringBuilder(" ");
if (primary != null)
{
if (primary.KnownPrimaryType == KnownPrimaryType.Int || primary.KnownPrimaryType == KnownPrimaryType.Long)
{
return builder.AppendLine("{0} = Integer({0}) unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.Double)
{
return builder.AppendLine("{0} = Float({0}) unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.ByteArray)
{
return builder.AppendLine("{0} = Base64.strict_decode64({0}).unpack('C*') unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.Date)
{
return builder.AppendLine("{0} = MsRest::Serialization.deserialize_date({0}) unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.DateTime)
{
return builder.AppendLine("{0} = DateTime.parse({0}) unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.DateTimeRfc1123)
{
return builder.AppendLine("{0} = DateTime.parse({0}) unless {0}.to_s.empty?", valueReference).ToString();
}
if (primary.KnownPrimaryType == KnownPrimaryType.UnixTime)
{
return builder.AppendLine("{0} = DateTime.strptime({0}.to_s, '%s') unless {0}.to_s.empty?", valueReference).ToString();
}
}
else if (enumType != null && !string.IsNullOrEmpty(enumType.Name))
{
return builder
.AppendLine("if (!{0}.nil? && !{0}.empty?)", valueReference)
.AppendLine(
" enum_is_valid = {0}.constants.any? {{ |e| {0}.const_get(e).to_s.downcase == {1}.downcase }}",
enumType.ModuleName, valueReference)
.AppendLine(
" warn 'Enum {0} does not contain ' + {1}.downcase + ', but was received from the server.' unless enum_is_valid", enumType.ModuleName, valueReference)
.AppendLine("end")
.ToString();
}
else if (sequence != null)
{
var elementVar = scope.GetUniqueName("element");
var innerSerialization = sequence.ElementType.AzureDeserializeType(scope, elementVar);
if (!string.IsNullOrEmpty(innerSerialization))
{
return
builder
.AppendLine("unless {0}.nil?", valueReference)
.Indent()
.AppendLine("deserialized_{0} = []", sequence.Name.ToLower())
.AppendLine("{0}.each do |{1}|", valueReference, elementVar)
.Indent()
.AppendLine(innerSerialization)
.AppendLine("deserialized_{0}.push({1})", sequence.Name.ToLower(), elementVar)
.Outdent()
.AppendLine("end")
.AppendLine("{0} = deserialized_{1}", valueReference, sequence.Name.ToLower())
.Outdent()
.AppendLine("end")
.ToString();
}
}
else if (dictionary != null)
{
var valueVar = scope.GetUniqueName("valueElement");
var innerSerialization = dictionary.ValueType.AzureDeserializeType(scope, valueVar);
if (!string.IsNullOrEmpty(innerSerialization))
{
return builder.AppendLine("unless {0}.nil?", valueReference)
//.........这里部分代码省略.........
开发者ID:devigned,项目名称:autorest,代码行数:101,代码来源:AzureClientModelExtensions.cs
注:本文中的AutoRest.Core.Utilities.IndentedStringBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论