Skip to content

Commit 6342d1f

Browse files
author
Caitlin Bales (MSFT)
committed
Replace remaining DataMember references
1 parent d44463f commit 6342d1f

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Templates/CSharp/Requests/EntityCollectionResponse.cs.tt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ namespace <#=prop.Class.AsOdcmClass().Namespace.GetNamespaceName()#>
1919
/// <summary>
2020
/// The type <#=collectionResponse#>.
2121
/// </summary>
22-
[DataContract]
22+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
23+
<#
24+
// We only want to add the derived type converter to the classes at the top of the inheritance hierarchy
25+
if (prop.Class.Derived != null && prop.Class.Base == null)
26+
{ #>
27+
[JsonConverter(typeof(DerivedTypeConverter))]
28+
<# } #>
2329
public class <#=collectionResponse#>
2430
{
2531
/// <summary>
2632
/// Gets or sets the <see cref="I<#=collectionPage#>"/> value.
2733
/// </summary>
28-
[DataMember(Name = "value", EmitDefaultValue = false, IsRequired = false)]
34+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Required.Default)]
2935
public I<#=collectionPage#> Value { get; set; }
3036

3137
/// <summary>

Templates/CSharp/Requests/EntityCollectionWithReferencesResponse.cs.tt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ namespace <#=prop.Class.AsOdcmClass().Namespace.GetNamespaceName()#>
1919
/// <summary>
2020
/// The type <#=collectionResponse#>.
2121
/// </summary>
22-
[DataContract]
22+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
23+
<#
24+
// We only want to add the derived type converter to the classes at the top of the inheritance hierarchy
25+
if (prop.Class.Derived != null && prop.Class.Base == null)
26+
{ #>
27+
[JsonConverter(typeof(DerivedTypeConverter))]
28+
<# } #>
2329
public class <#=collectionResponse#>
2430
{
2531
/// <summary>
2632
/// Gets or sets the <see cref="I<#=collectionPage#>"/> value.
2733
/// </summary>
28-
[DataMember(Name = "value", EmitDefaultValue = false, IsRequired = false)]
34+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Required.Default)]
2935
public I<#=collectionPage#> Value { get; set; }
3036

3137
/// <summary>

Templates/CSharp/Requests/MethodCollectionResponse.cs.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ namespace <#=method.Namespace.GetNamespaceName()#>
2222
/// <summary>
2323
/// The type <#=collectionResponse#>.
2424
/// </summary>
25-
[DataContract]
25+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
2626
public class <#=collectionResponse#>
2727
{
2828
/// <summary>
2929
/// Gets or sets the <see cref="I<#=collectionPage#>"/> value.
3030
/// </summary>
31-
[DataMember(Name = "value", EmitDefaultValue = false, IsRequired = false)]
31+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="value", Required = Required.Default)]
3232
public I<#=collectionPage#> Value { get; set; }
3333
<#
3434
if (isSpecialCollection)
@@ -44,7 +44,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
4444
/// <summary>
4545
/// Gets or sets the <#=propertyName#>.
4646
/// </summary>
47-
[DataMember(Name = "<#=property.Name#>", EmitDefaultValue = false, IsRequired = false)]
47+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName ="<#=property.Name#>", Required = Required.Default)]
4848
public <#=propertyType#> <#=propertyName#> { get; set; }
4949
<#
5050
}

0 commit comments

Comments
 (0)