本文整理汇总了C#中AutoRest.Core.Utilities.IndentedStringBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IndentedStringBuilder.ToString方法的具体用法?C# IndentedStringBuilder.ToString怎么用?C# IndentedStringBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoRest.Core.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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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(" ");
BuildPathParameters(variableName, builder);
RemoveDuplicateForwardSlashes("requestUrl", builder);
if (HasQueryParameters())
{
BuildQueryParameterArray(builder);
AddQueryParametersToUrl(variableName, builder);
}
return builder.ToString();
}
示例6: 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();
}
示例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();
}
示例8: 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();
}
示例9: ContructMapperForEnumType
/// <summary>
/// Constructs blueprint of the given <paramref name="enumeration"/>.
/// </summary>
/// <param name="enumeration">EnumType for which mapper being generated.</param>
/// <returns>Mapper for the <paramref name="enumeration"/> as string.</returns>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
/// <example>
/// The below example shows possible mapper string for EnumType.
/// type: {
/// name: 'Enum',
/// module: 'module_name' -- name of the module to be looked for enum values
/// }
/// </example>
private static string ContructMapperForEnumType(this EnumTypeRb enumeration)
{
if (enumeration == null)
{
throw new ArgumentNullException(nameof(enumeration));
}
IndentedStringBuilder builder = new IndentedStringBuilder(" ");
builder.AppendLine("type: {").Indent()
.AppendLine("name: 'Enum',")
.AppendLine("module: '{0}'", enumeration.ModuleName).Outdent()
.AppendLine("}");
return builder.ToString();
}
示例10: ContructMapperForPrimaryType
/// <summary>
/// Constructs blueprint of the given <paramref name="primary"/>.
/// </summary>
/// <param name="primary">PrimaryType for which mapper being generated.</param>
/// <returns>Mapper for the <paramref name="primary"/> as string.</returns>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
/// <example>
/// The below example shows possible mapper string for PrimaryType.
/// type: {
/// name: 'Boolean' -- This value should be one of the KnownPrimaryType
/// }
/// </example>
private static string ContructMapperForPrimaryType(this PrimaryType primary)
{
if (primary == null)
{
throw new ArgumentNullException(nameof(primary));
}
IndentedStringBuilder builder = new IndentedStringBuilder(" ");
if (primary.KnownPrimaryType == KnownPrimaryType.Boolean)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Boolean'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Double)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Double'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Int || primary.KnownPrimaryType == KnownPrimaryType.Long ||
primary.KnownPrimaryType == KnownPrimaryType.Decimal)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Number'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.String || primary.KnownPrimaryType == KnownPrimaryType.Uuid)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'String'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.ByteArray)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'ByteArray'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Base64Url)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Base64Url'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Date)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Date'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.DateTime)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'DateTime'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.DateTimeRfc1123)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'DateTimeRfc1123'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.TimeSpan)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'TimeSpan'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.UnixTime)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'UnixTime'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Object)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Object'").Outdent().AppendLine("}");
}
else if (primary.KnownPrimaryType == KnownPrimaryType.Stream)
{
builder.AppendLine("type: {").Indent().AppendLine("name: 'Stream'").Outdent().AppendLine("}");
}
else
{
throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "{0} is not a supported primary Type for {1}.", primary.KnownPrimaryType, primary.SerializedName));
}
return builder.ToString();
}
示例11: AddMetaData
//.........这里部分代码省略.........
/// <param name="serializedName">Serialized name to be used.</param>
/// <param name="parameter">Parameter of the composite type to construct the parameter constraints.</param>
/// <returns>Metadata as string.</returns>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
/// <example>
/// The below example shows possible mapper string for IParameter for IModelType.
/// required: true | false, -- whether this property is required or not
/// read_only: true | false, -- whether this property is read only or not. Default is false
/// is_constant: true | false, -- whether this property is constant or not. Default is false
/// serialized_name: 'name' -- serialized name of the property if provided
/// default_value: 'value' -- default value of the property if provided
/// constraints: { -- constraints of the property
/// key: value, -- constraint name and value if any
/// ***: *****
/// }
/// </example>
private static string AddMetaData(this IModelType type, string serializedName, IVariable parameter)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
IndentedStringBuilder builder = new IndentedStringBuilder(" ");
Dictionary<Constraint, string> constraints = null;
string defaultValue = null;
bool isRequired = false;
bool isConstant = false;
bool isReadOnly = false;
var property = parameter as Property;
if (property != null)
{
isReadOnly = property.IsReadOnly;
}
if (parameter != null)
{
defaultValue = parameter.DefaultValue;
isRequired = parameter.IsRequired;
isConstant = parameter.IsConstant;
constraints = parameter.Constraints;
}
CompositeType composite = type as CompositeType;
if (composite != null && composite.ContainsConstantProperties && isRequired)
{
defaultValue = "{}";
}
if (isRequired)
{
builder.AppendLine("required: true,");
}
else
{
builder.AppendLine("required: false,");
}
if (isReadOnly)
{
builder.AppendLine("read_only: true,");
}
if (isConstant)
{
builder.AppendLine("is_constant: true,");
}
if (serializedName != null)
{
builder.AppendLine("serialized_name: '{0}',", serializedName);
}
if (defaultValue != null)
{
builder.AppendLine("default_value: {0},", defaultValue);
}
if (constraints != null && constraints.Count > 0)
{
builder.AppendLine("constraints: {").Indent();
var keys = constraints.Keys.ToList<Constraint>();
for (int j = 0; j < keys.Count; j++)
{
var constraintValue = constraints[keys[j]];
if (keys[j] == Constraint.Pattern)
{
constraintValue = string.Format(CultureInfo.InvariantCulture, "'{0}'", constraintValue);
}
if (j != keys.Count - 1)
{
builder.AppendLine("{0}: {1},", keys[j], constraintValue);
}
else
{
builder.AppendLine("{0}: {1}", keys[j], constraintValue);
}
}
builder.Outdent()
.AppendLine("},");
}
return builder.ToString();
}
示例12: ConstructMapper
//.........这里部分代码省略.........
/// <param name="type">Type for which mapper being generated.</param>
/// <param name="serializedName">Serialized name to be used.</param>
/// <param name="parameter">Parameter of the composite type to construct the parameter constraints.</param>
/// <param name="expandComposite">Expand composite type if <c>true</c> otherwise specify class_name in the mapper.</param>
/// <returns>Mapper for the <paramref name="type"/> as string.</returns>
/// <exception cref="ArgumentNullException">Thrown when a required parameter is null.</exception>
/// <example>
/// One of the example of the mapper is
/// {
/// required: false,
/// serialized_name: 'Fish',
/// type: {
/// name: 'Composite',
/// polymorphic_discriminator: 'fishtype',
/// uber_parent: 'Fish',
/// class_name: 'Fish',
/// model_properties: {
/// species: {
/// required: false,
/// serialized_name: 'species',
/// type: {
/// name: 'String'
/// }
/// },
/// length: {
/// required: true,
/// serialized_name: 'length',
/// type: {
/// name: 'Double'
/// }
/// },
/// siblings: {
/// required: false,
/// serialized_name: 'siblings',
/// type: {
/// name: 'Sequence',
/// element: {
/// required: false,
/// serialized_name: 'FishElementType',
/// type: {
/// name: 'Composite',
/// polymorphic_discriminator: 'fishtype',
/// uber_parent: 'Fish',
/// class_name: 'Fish'
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// </example>
public static string ConstructMapper(this IModelType type, string serializedName, IVariable parameter, bool expandComposite)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
var builder = new IndentedStringBuilder(" ");
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;
if (enumType != null && enumType.ModelAsString)
{
primary = New<PrimaryType>(KnownPrimaryType.String);
}
builder.AppendLine("").Indent();
builder.AppendLine(type.AddMetaData(serializedName, parameter));
if (primary != null)
{
builder.AppendLine(primary.ContructMapperForPrimaryType());
}
else if (enumType != null && enumType.Name != null)
{
builder.AppendLine(((EnumTypeRb)enumType).ContructMapperForEnumType());
}
else if (sequence != null)
{
builder.AppendLine(sequence.ContructMapperForSequenceType());
}
else if (dictionary != null)
{
builder.AppendLine(dictionary.ContructMapperForDictionaryType());
}
else if (composite != null)
{
builder.AppendLine(composite.ContructMapperForCompositeType(expandComposite));
}
else
{
throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "{0} is not a supported Type.", type));
}
return builder.ToString();
}
示例13: BuildInputMappings
/// <summary>
/// Generates input mapping code block.
/// </summary>
/// <returns></returns>
public virtual string BuildInputMappings()
{
var builder = new IndentedStringBuilder(" ");
foreach (var transformation in InputParameterTransformation)
{
if (transformation.ParameterMappings.Any(m => !string.IsNullOrEmpty(m.OutputParameterProperty)) &&
transformation.OutputParameter.ModelType is CompositeType)
{
var comps = CodeModel.ModelTypes.Where(x => x.Name == transformation.OutputParameter.ModelTypeName);
var composite = comps.First();
List<string> combinedParams = new List<string>();
List<string> paramCheck = new List<string>();
foreach (var mapping in transformation.ParameterMappings)
{
// var mappedParams = composite.ComposedProperties.Where(x => x.Name.RawValue == mapping.InputParameter.Name.RawValue);
var mappedParams = composite.ComposedProperties.Where(x => x.Name == mapping.InputParameter.Name);
if (mappedParams.Any())
{
var param = mappedParams.First();
combinedParams.Add(string.Format(CultureInfo.InvariantCulture, "{0}={0}", param.Name));
paramCheck.Add(string.Format(CultureInfo.InvariantCulture, "{0} is not None", param.Name));
}
}
if (!transformation.OutputParameter.IsRequired)
{
builder.AppendLine("{0} = None", transformation.OutputParameter.Name);
builder.AppendLine("if {0}:", string.Join(" or ", paramCheck)).Indent();
}
builder.AppendLine("{0} = models.{1}({2})",
transformation.OutputParameter.Name,
transformation.OutputParameter.ModelType.Name,
string.Join(", ", combinedParams));
}
else
{
builder.AppendLine("{0} = None",
transformation.OutputParameter.Name);
builder.AppendLine("if {0}:", BuildNullCheckExpression(transformation))
.Indent();
foreach (var mapping in transformation.ParameterMappings)
{
builder.AppendLine("{0}{1}",
transformation.OutputParameter.Name,
mapping);
}
builder.Outdent();
}
}
return builder.ToString();
}
示例14: AddIndividualResponseHeader
public virtual string AddIndividualResponseHeader(HttpStatusCode? code)
{
IModelType 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();
}
示例15: AddResponseHeader
public virtual string AddResponseHeader()
{
if (HasResponseHeader)
{
var builder = new IndentedStringBuilder(" ");
builder.AppendLine("client_raw_response.add_headers(header_dict)");
return builder.ToString();
}
else
{
return string.Empty;
}
}