Skip to content

Commit

Permalink
Fix headers deserialization. (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT authored Aug 21, 2018
1 parent 1ab1029 commit 9082d54
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/csharp/lowlevel-generator/model/model-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ export class ModelClass extends Class implements EnhancedTypeDeclaration {
for (const hp of headerProperties) {
const hparam = <ModelProperty>hp;
const values = `__${camelCase(['header', ...deconstruct(hparam.serializedName)])}Values`;
const tmp = `__${camelCase(['header', ...deconstruct(hparam.serializedName)])}`;
yield If(`${valueOf(headers)}.TryGetValues("${hparam.serializedName}", out var ${values})`, `${hparam.backingName} = System.Linq.Enumerable.FirstOrDefault(${values}) is string ${tmp} ? ${tmp} : (string)${hparam.name})`);
yield If(`${valueOf(headers)}.TryGetValues("${hparam.serializedName}", out var ${values})`, `${hparam.assignPrivate(hparam.deserializeFromContainerMember(KnownMediaType.Header, headers, values))}`);
}
yield `return this;`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/schema/date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class DateTime extends Primitive {
super(schema);
}
// public static string DateFormat = "yyyy-MM-dd";
// public static string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
// public static string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
// public static string DateTimeRfc1123Format = "R";
// public static JsonString CreateDate(DateTime? value) => value is DateTime date ? new JsonString(date.ToString(DateFormat, CultureInfo.InvariantCulture)) : null;
// public static JsonString CreateDateTime(DateTime? value) => value is DateTime date ? new JsonString(date.ToString(DateTimeFormat, CultureInfo.InvariantCulture)) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/schema/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export abstract class Primitive implements EnhancedTypeDeclaration {
case KnownMediaType.Header: {
// HttpResponseHeaders
const tmp = `__${camelCase(['header', ...deconstruct(serializedName)])}`;
return toExpression(`System.Linq.Enumerable.FirstOrDefault(${valueOf(container)}.GetValues("${serializedName}")) is string ${tmp} ? ${this.baseType}.TryParse( ${tmp}, out ${this.baseType} ${tmp}Value ) ? ${tmp}Value :${defaultValue}:${defaultValue}`);
return toExpression(`System.Linq.Enumerable.FirstOrDefault(${serializedName}) is string ${tmp} ? ${this.baseType}.TryParse( ${tmp}, out ${this.baseType} ${tmp}Value ) ? ${tmp}Value : ${defaultValue} : ${defaultValue}`);
}
}
return toExpression(`${defaultValue} /* deserializeFromContainerMember doesn't support '${mediaType}' ${__filename} */`);
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/schema/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class String implements EnhancedTypeDeclaration {
case KnownMediaType.Header: {
// HttpResponseHeaders
const tmp = `__${camelCase(['header', ...deconstruct(serializedName)])}`;
return toExpression(`System.Linq.Enumerable.FirstOrDefault(${valueOf(container)}.GetValues("${serializedName}")) is string ${tmp} ? ${tmp} :(string)${defaultValue}`);
return toExpression(`System.Linq.Enumerable.FirstOrDefault(${serializedName}) is string ${tmp} ? ${tmp} : (string)${defaultValue}`);
}
}
return toExpression(`${defaultValue} /* deserializeFromContainerMember doesn't support '${mediaType}' ${__filename}*/`);
Expand Down

0 comments on commit 9082d54

Please sign in to comment.