本文整理汇总了C#中Microsoft.Rest.Generator.Utilities.IndentedStringBuilder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# IndentedStringBuilder.Append方法的具体用法?C# IndentedStringBuilder.Append怎么用?C# IndentedStringBuilder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Rest.Generator.Utilities.IndentedStringBuilder
的用法示例。
在下文中一共展示了IndentedStringBuilder.Append方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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.GetVariableName("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("}")
.Outdent()
.AppendLine("}");
if (isRequired)
{
builder.Append(" else {")
.Indent()
.AppendLine("throw new Error('{0} cannot be null or undefined.');", valueReference)
.Outdent()
.AppendLine("}");
}
return builder.ToString();
}
示例3: 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();
}
示例4: SerializeEnumType
private static string SerializeEnumType(this EnumType enumType, IScopeProvider scope, string objectReference, string valueReference, bool isRequired)
{
if (scope == null)
{
throw new ArgumentNullException("scope");
}
var builder = new IndentedStringBuilder(" ");
var allowedValues = scope.GetVariableName("allowedValues");
string tempReference = objectReference;
builder.AppendLine("if ({0} !== null && {0} !== undefined) {{", objectReference)
.Indent()
.AppendLine("var {0} = {1};", allowedValues, enumType.GetEnumValuesArray());
if (objectReference.IndexOfAny(new char[] { '.', '[', ']'}) >= 0)
{
tempReference = tempReference.NormalizeValueReference();
builder.AppendLine("var {0} = {1};", tempReference, objectReference);
}
builder.AppendLine("if (!{0}.some( function(item) {{ return item === {1}; }})) {{", allowedValues, tempReference)
.Indent()
.AppendLine("throw new Error({0} + ' is not a valid value. The valid values are: ' + {1});", objectReference, allowedValues)
.Outdent()
.AppendLine("}");
builder = ConstructBasePropertyCheck(builder, valueReference);
builder.AppendLine("{0} = {1};", valueReference, objectReference)
.Outdent()
.AppendLine("}");
if (isRequired)
{
builder.Append(" else {")
.Indent()
.AppendLine("throw new Error('{0} cannot be null or undefined.');", objectReference)
.Outdent()
.AppendLine("}");
}
return builder.ToString();
}