Skip to content

Commit 301b345

Browse files
committed
Add EdmDateConverter attribute for Edm.Date properties
1 parent 4b9d927 commit 301b345

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Templates/CSharp/Model/ComplexType.cs.tt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ namespace <#=complex.Namespace.GetNamespaceName()#>
5050
var propertyName = isMethodResponse
5151
? property.Name.Substring(property.Name.IndexOf('.') + 1).ToCheckedCase()
5252
: property.Name.ToCheckedCase().GetSanitizedPropertyName();
53+
54+
var attributeDefinition = string.Format("[DataMember(Name = \"{0}\", EmitDefaultValue = false, IsRequired = false)]", property.Name);
55+
56+
if (string.Equals(property.Type.FullName, "Edm.Date", StringComparison.OrdinalIgnoreCase))
57+
{
58+
attributeDefinition = string.Concat("[EdmDateConverter]", Environment.NewLine, " ", attributeDefinition);
59+
}
5360

5461
if (property.IsTypeNullable() || property.IsCollection)
5562
{
@@ -58,7 +65,7 @@ namespace <#=complex.Namespace.GetNamespaceName()#>
5865
/// <summary>
5966
/// Gets or sets <#=property.Name#>.
6067
/// </summary>
61-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
68+
<#=attributeDefinition#>
6269
public <#=propertyType#> <#=propertyName#> { get; set; }
6370
<#
6471
}
@@ -69,7 +76,7 @@ namespace <#=complex.Namespace.GetNamespaceName()#>
6976
/// <summary>
7077
/// Gets or sets <#=property.Name#>.
7178
/// </summary>
72-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
79+
<#=attributeDefinition#>
7380
public <#=propertyType#>? <#=propertyName#> { get; set; }
7481
<#
7582
}

Templates/CSharp/Model/EntityType.cs.tt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
6060

6161
var propertyName = property.Name.ToCheckedCase();
6262
var propertyCollectionPage = property.IsReference() ? string.Concat(entityName, propertyName, "CollectionWithReferencesPage") : string.Concat(entityName, propertyName, "CollectionPage");
63+
64+
var attributeDefinition = string.Format("[DataMember(Name = \"{0}\", EmitDefaultValue = false, IsRequired = false)]", property.Name);
65+
66+
if (string.Equals(property.Type.FullName, "Edm.Date", StringComparison.OrdinalIgnoreCase))
67+
{
68+
attributeDefinition = string.Concat("[EdmDateConverter]", Environment.NewLine, " ", attributeDefinition);
69+
}
6370

6471
if (property.IsCollection())
6572
{
@@ -70,7 +77,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
7077
/// <summary>
7178
/// Gets or sets <#=property.Name.SplitCamelCase().ToLower()#>.
7279
/// </summary>
73-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
80+
<#=attributeDefinition#>
7481
public I<#=propertyCollectionPage#> <#=propertyName.GetSanitizedPropertyName()#> { get; set; }
7582
<#
7683
}
@@ -81,7 +88,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
8188
/// <summary>
8289
/// Gets or sets <#=property.Name.SplitCamelCase().ToLower()#>.
8390
/// </summary>
84-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
91+
<#=attributeDefinition#>
8592
public IEnumerable<<#=propertyType#>> <#=propertyName.GetSanitizedPropertyName()#> { get; set; }
8693
<#
8794
}
@@ -93,7 +100,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
93100
/// <summary>
94101
/// Gets or sets <#=property.Name.SplitCamelCase().ToLower()#>.
95102
/// </summary>
96-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
103+
<#=attributeDefinition#>
97104
public <#=propertyType#> <#=propertyName.GetSanitizedPropertyName()#> { get; set; }
98105
<#
99106
}

0 commit comments

Comments
 (0)