diff --git a/powershell/llcsharp/schema/array.ts b/powershell/llcsharp/schema/array.ts index eb00cd7e80..3bf5d14af6 100644 --- a/powershell/llcsharp/schema/array.ts +++ b/powershell/llcsharp/schema/array.ts @@ -165,7 +165,8 @@ export class ArrayOf implements EnhancedTypeDeclaration { } case KnownMediaType.Cookie: case KnownMediaType.QueryParameter: - return toExpression(`(null != ${value} && ${value}.Count > 0 ? "${serializedName}=" + ${this.encode}(global::System.Linq.Enumerable.Aggregate(${value}, (current, each) => current + "," + ( ${this.encode}(null == each ? ${System.String.Empty} : each.ToString()) ))) : ${System.String.Empty})`); + var formatSerializedName = serializedName ? `${serializedName}=` : ''; + return toExpression(`(null != ${value} && ${value}.Count > 0 ? "${formatSerializedName}" + ${this.encode}(global::System.Linq.Enumerable.Aggregate(${value}, (current, each) => current + "," + ( ${this.encode}(null == each ? ${System.String.Empty} : each.ToString()) ))) : ${System.String.Empty})`); case KnownMediaType.Header: case KnownMediaType.Text: case KnownMediaType.UriParameter: diff --git a/powershell/llcsharp/schema/date-time.ts b/powershell/llcsharp/schema/date-time.ts index 63a43c2899..da5e5122a4 100644 --- a/powershell/llcsharp/schema/date-time.ts +++ b/powershell/llcsharp/schema/date-time.ts @@ -55,14 +55,16 @@ export class DateTime extends NewPrimitive { case KnownMediaType.Header: case KnownMediaType.Text: case KnownMediaType.UriParameter: + var formatSerializedName = serializedName ? `${serializedName}=` : ''; return toExpression(this.isRequired ? - `"${serializedName}=" + ${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)` : - `(null == ${value} ? ${System.String.Empty} : "${serializedName}=" + ${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture))` + `"${formatSerializedName}" + ${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)` : + `(null == ${value} ? ${System.String.Empty} : "${formatSerializedName}" + ${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture))` ); } return toExpression(`null /* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); } serializeToContainerMember(mediaType: KnownMediaType, value: ExpressionOrLiteral, container: Variable, serializedName: string, mode: Expression): OneOrMoreStatements { + var formatSerializedName = serializedName ? `${serializedName}=` : ''; switch (mediaType) { case KnownMediaType.Json: // container : JsonObject @@ -81,14 +83,14 @@ export class DateTime extends NewPrimitive { case KnownMediaType.QueryParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `${serializedName}={${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}` : - `{null == ${value} ? ${System.String.Empty} : $"${serializedName}={${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}"}`; + `${formatSerializedName}{${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}` : + `{null == ${value} ? ${System.String.Empty} : $"${formatSerializedName}{${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}"}`; case KnownMediaType.UriParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `${serializedName}={${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}` : - `{null == ${value} ? ${System.String.Empty}: $"${serializedName}={${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}"}`; + `${formatSerializedName}{${value}.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}` : + `{null == ${value} ? ${System.String.Empty}: $"${formatSerializedName}{${value}?.ToString(${this.DateTimeFormat},global::System.Globalization.CultureInfo.InvariantCulture)}"}`; } return (`/* serializeToContainerMember doesn't support '${mediaType}' ${__filename}*/`); } @@ -134,6 +136,7 @@ export class UnixTime extends NewPrimitive { } serializeToNode(mediaType: KnownMediaType, value: ExpressionOrLiteral, serializedName: string, mode: Expression): Expression { + var formatSerializedName = serializedName ? `${serializedName}=` : ''; switch (mediaType) { case KnownMediaType.Json: return this.isRequired ? @@ -147,12 +150,12 @@ export class UnixTime extends NewPrimitive { case KnownMediaType.QueryParameter: if (this.isRequired) { - return toExpression(`"${serializedName}=" + ${this.encode}(${value}.ToString())`); + return toExpression(`"${formatSerializedName}" + ${this.encode}(${value}.ToString())`); } else { - return toExpression(`(null == ${value} ? ${System.String.Empty} : "${serializedName}=" + ${this.encode}(${value}.ToString()))`); + return toExpression(`(null == ${value} ? ${System.String.Empty} : "${formatSerializedName}" + ${this.encode}(${value}.ToString()))`); } - // return toExpression(`if (${value} != null) { queryParameters.Add($"${value}={${value}}"); }`); + // return toExpression(`if (${value} != null) { queryParameters.Add($"${value}={${value}}"); }`); case KnownMediaType.Cookie: case KnownMediaType.Header: diff --git a/powershell/llcsharp/schema/duration.ts b/powershell/llcsharp/schema/duration.ts index 711398f9a5..c476656060 100644 --- a/powershell/llcsharp/schema/duration.ts +++ b/powershell/llcsharp/schema/duration.ts @@ -46,10 +46,11 @@ export class Duration extends NewPrimitive { return toExpression(`${ClientRuntime.JsonString.new(`global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})`)}`).Cast(ClientRuntime.JsonNode); case KnownMediaType.QueryParameter: + var formatSerializedName = serializedName ? `${serializedName}=` : ''; if (this.isRequired) { - return toExpression(`"${serializedName}=" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value}))`); + return toExpression(`"${formatSerializedName}" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value}))`); } else { - return toExpression(`(null == ${value} ? ${System.String.Empty} : "${serializedName}=" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})))`); + return toExpression(`(null == ${value} ? ${System.String.Empty} : "${formatSerializedName}" + ${this.encode}(global::System.Xml.XmlConvert.ToString((global::System.TimeSpan)${value})))`); } } return toExpression(`/* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); diff --git a/powershell/llcsharp/schema/fixed-array.ts b/powershell/llcsharp/schema/fixed-array.ts index b923785946..2a15c0256c 100644 --- a/powershell/llcsharp/schema/fixed-array.ts +++ b/powershell/llcsharp/schema/fixed-array.ts @@ -165,7 +165,8 @@ export class FixedArrayOf implements EnhancedTypeDeclaration { } case KnownMediaType.Cookie: case KnownMediaType.QueryParameter: - return toExpression(`(null != ${value} && ${value}.Length > 0 ? "${serializedName}=" + ${this.encode}(global::System.Linq.Enumerable.Aggregate(${value}, (current, each) => current + "," + ( ${this.encode}(null == each ? ${System.String.Empty} : each.ToString()) ))) : ${System.String.Empty})`); + var formatSerializedName = serializedName ? `${serializedName}=` : ''; + return toExpression(`(null != ${value} && ${value}.Length > 0 ? "${formatSerializedName}" + ${this.encode}(global::System.Linq.Enumerable.Aggregate(${value}, (current, each) => current + "," + ( ${this.encode}(null == each ? ${System.String.Empty} : each.ToString()) ))) : ${System.String.Empty})`); case KnownMediaType.Header: case KnownMediaType.Text: case KnownMediaType.UriParameter: diff --git a/powershell/llcsharp/schema/primitive.ts b/powershell/llcsharp/schema/primitive.ts index 60ce81387d..c3c0fdaa58 100644 --- a/powershell/llcsharp/schema/primitive.ts +++ b/powershell/llcsharp/schema/primitive.ts @@ -186,13 +186,14 @@ export abstract class NewPrimitive implements EnhancedTypeDeclaration { toExpression(`null != ${value} ? new ${System.Xml.Linq.XElement}("${serializedName}",${value}) : null`); case KnownMediaType.QueryParameter: + var formatSerializedName = serializedName ? `${serializedName}=` : ''; if (this.isRequired) { - return toExpression(`"${serializedName}=" + ${this.encode}(${value}.ToString())`); + return toExpression(`"${formatSerializedName}" + ${this.encode}(${value}.ToString())`); } else { - return toExpression(`(null == ${value} ? ${System.String.Empty} : "${serializedName}=" + ${this.encode}(${value}.ToString()))`); + return toExpression(`(null == ${value} ? ${System.String.Empty} : "${formatSerializedName}" + ${this.encode}(${value}.ToString()))`); } - // return toExpression(`if (${value} != null) { queryParameters.Add($"${value}={${value}}"); }`); + // return toExpression(`if (${value} != null) { queryParameters.Add($"${value}={${value}}"); }`); case KnownMediaType.Cookie: case KnownMediaType.Header: @@ -206,6 +207,7 @@ export abstract class NewPrimitive implements EnhancedTypeDeclaration { return toExpression(`null /* serializeToNode doesn't support '${mediaType}' ${__filename}*/`); } serializeToContainerMember(mediaType: KnownMediaType, value: ExpressionOrLiteral, container: Variable, serializedName: string, mode: Expression): OneOrMoreStatements { + var formatSerializedName = serializedName ? `${serializedName}=` : ''; switch (mediaType) { case KnownMediaType.Json: // container : JsonObject @@ -224,14 +226,14 @@ export abstract class NewPrimitive implements EnhancedTypeDeclaration { case KnownMediaType.QueryParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `${serializedName}={${value}.ToString()}` : + `${formatSerializedName}{${value}.ToString()}` : `{null == ${value} ? ${System.String.Empty} : $"${serializedName}={${value}.ToString()}"}`; case KnownMediaType.UriParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `${serializedName}={${value}.ToString()}` : - `{null == ${value} ? ${System.String.Empty}: $"${serializedName}={${value}.ToString()}"}`; + `${formatSerializedName}{${value}.ToString()}` : + `{null == ${value} ? ${System.String.Empty}: $"${formatSerializedName}{${value}.ToString()}"}`; } return (`/* serializeToContainerMember doesn't support '${mediaType}' ${__filename}*/`); } diff --git a/powershell/llcsharp/schema/string.ts b/powershell/llcsharp/schema/string.ts index 0bb2229d97..78b6770c78 100644 --- a/powershell/llcsharp/schema/string.ts +++ b/powershell/llcsharp/schema/string.ts @@ -87,11 +87,11 @@ export class String implements EnhancedTypeDeclaration { return toExpression(`null != (${value}?.ToString()) ? new ${System.Xml.Linq.XElement}("${serializedName}",${value}) : null`); case KnownMediaType.QueryParameter: - + var formatSerializedName = serializedName ? `${serializedName}=` : ''; if (this.isRequired) { - return toExpression(`"${serializedName}=" + ${this.encode}(${value})`); + return toExpression(`"${formatSerializedName}" + ${this.encode}(${value})`); } else { - return toExpression(`(string.IsNullOrEmpty(${value}) ? ${System.String.Empty} : "${serializedName}=" + ${this.encode}(${valueOf(value)}))`); + return toExpression(`(string.IsNullOrEmpty(${value}) ? ${System.String.Empty} : "${formatSerializedName}" + ${this.encode}(${valueOf(value)}))`); } case KnownMediaType.Cookie: @@ -135,6 +135,7 @@ export class String implements EnhancedTypeDeclaration { } serializeToContainerMember(mediaType: KnownMediaType, value: ExpressionOrLiteral, container: Variable, serializedName: string, mode: Expression): OneOrMoreStatements { + var formatSerializedName = serializedName ? `${serializedName}=` : ''; switch (mediaType) { case KnownMediaType.Json: return `AddIf( ${this.serializeToNode(mediaType, value, serializedName, mode)}, "${serializedName}" ,${container}.Add );`; @@ -151,14 +152,14 @@ export class String implements EnhancedTypeDeclaration { case KnownMediaType.QueryParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `${serializedName}={${value}.ToString()}` : - `{null == ${value} ? ${System.String.Empty} : $"${serializedName}={${value}.ToString()}"}`; + `${formatSerializedName}{${value}.ToString()}` : + `{null == ${value} ? ${System.String.Empty} : $"${formatSerializedName}{${value}.ToString()}"}`; case KnownMediaType.UriParameter: // gives a name=value for use inside a c# template string($"foo{someProperty}") as a query parameter return this.isRequired ? - `(${serializedName}={${value}.ToString()})` : - `(null == ${value} ? ${System.String.Empty}: $"${serializedName}={${value}.ToString()}")`; + `(${formatSerializedName}{${value}.ToString()})` : + `(null == ${value} ? ${System.String.Empty}: $"${formatSerializedName}{${value}.ToString()}")`; } return (`/* serializeToContainerMember doesn't support '${mediaType}' ${__filename}*/`); }