Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion powershell/llcsharp/schema/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 12 additions & 9 deletions powershell/llcsharp/schema/date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}*/`);
}
Expand Down Expand Up @@ -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 ?
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions powershell/llcsharp/schema/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}*/`);
Expand Down
3 changes: 2 additions & 1 deletion powershell/llcsharp/schema/fixed-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions powershell/llcsharp/schema/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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}*/`);
}
Expand Down
15 changes: 8 additions & 7 deletions powershell/llcsharp/schema/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 );`;
Expand All @@ -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}*/`);
}
Expand Down