From 8673c39e5eb54bb9ae78707653a9e55b523905f7 Mon Sep 17 00:00:00 2001 From: Markus Bux Date: Mon, 16 May 2022 21:52:28 +0200 Subject: [PATCH] Add Fix for OpenTypeProperties --- .../Templates/ODataT4CodeGenerator.cs | 26 +++++++++++---- .../Templates/ODataT4CodeGenerator.ttinclude | 9 ++++-- .../Templates/ODataT4CodeGenerator.cs | 1 + .../Templates/ODataT4CodeGenerator.ttinclude | 32 +++++++++++++++---- .../Templates/ODataT4CodeGenerator.ttinclude | 31 ++++++++++++++---- 5 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.cs diff --git a/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.cs b/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.cs index 43b07f4..3ddba77 100644 --- a/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.cs +++ b/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.cs @@ -1362,7 +1362,7 @@ public ODataClientTemplate(CodeGenerationContext context) internal abstract void WriteParameterNullCheckForStaticCreateMethod(string parameterName); internal abstract void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName); internal abstract void WriteMethodEndForStaticCreateMethod(string instanceName); - internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged); + internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType); internal abstract void WriteINotifyPropertyChangedImplementation(); internal abstract void WriteClassEndForStructuredType(); internal abstract void WriteNamespaceEnd(); @@ -2511,7 +2511,8 @@ internal void WritePropertiesForStructuredType(IEnumerable propert PropertyName = propertyName, FixedPropertyName = GetFixedName(propertyName), PrivatePropertyName = "_" + propertyName, - PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context) + PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context), + IsOpenTypeProperty = false }; }).ToList(); @@ -2524,7 +2525,8 @@ internal void WritePropertiesForStructuredType(IEnumerable propert PropertyName = this.context.DynamicPropertiesCollectionName, FixedPropertyName = GetFixedName(this.context.DynamicPropertiesCollectionName), PrivatePropertyName = "_" + Utils.CamelCase(this.context.DynamicPropertiesCollectionName), - PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName) + PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName), + IsOpenTypeProperty = true }); } @@ -2543,7 +2545,8 @@ internal void WritePropertiesForStructuredType(IEnumerable propert propertyInfo.FixedPropertyName, privatePropertyName, propertyInfo.PropertyInitializationValue, - useDataServiceCollection); + useDataServiceCollection, + propertyInfo.IsOpenTypeProperty); } } @@ -4517,7 +4520,7 @@ internal override void WriteMethodEndForStaticCreateMethod(string instanceName) } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { this.Write(" /// \r\n /// There are no comments for Property "); @@ -4531,8 +4534,13 @@ internal override void WritePropertyForStructuredType(string propertyType, strin this.Write("\")]\r\n"); + if (isOpenType) + { + this.Write(" [global::Microsoft.OData.Client.ContainerProperty]\r\n"); + } - if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) + + if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) { this.Write(" [global::Microsoft.OData.Client.OriginalNameAttribute(\""); @@ -6606,7 +6614,7 @@ internal override void WriteMethodEndForStaticCreateMethod(string instanceName) } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { this.Write(" \'\'\'\r\n \'\'\'There are no comments for Property "); @@ -6620,6 +6628,10 @@ internal override void WritePropertyForStructuredType(string propertyType, strin this.Write("\")> _\r\n"); + if(isOpenType) + { + this.Write(" \r\n"); + } if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) { diff --git a/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.ttinclude b/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.ttinclude index d3fda9e..a575e80 100644 --- a/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.ttinclude +++ b/src/Unchase.OData.ConnectedService.Shared/Templates/ODataT4CodeGenerator.ttinclude @@ -2440,7 +2440,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = propertyName, FixedPropertyName = GetFixedName(propertyName), PrivatePropertyName = "_" + propertyName, - PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context) + PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context), + IsOpenTypeProperty = false }; }).ToList(); @@ -2453,7 +2454,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = this.context.DynamicPropertiesCollectionName, FixedPropertyName = GetFixedName(this.context.DynamicPropertiesCollectionName), PrivatePropertyName = "_" + Utils.CamelCase(this.context.DynamicPropertiesCollectionName), - PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName) + PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName), + IsOpenTypeProperty = true }); } @@ -2472,7 +2474,8 @@ public abstract class ODataClientTemplate : TemplateBase propertyInfo.FixedPropertyName, privatePropertyName, propertyInfo.PropertyInitializationValue, - useDataServiceCollection); + useDataServiceCollection, + propertyInfo.IsOpenTypeProperty); } } diff --git a/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.cs b/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.ttinclude b/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.ttinclude index d3fda9e..c2c0679 100644 --- a/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.ttinclude +++ b/src/Unchase.OData.ConnectedService.VS22/Templates/ODataT4CodeGenerator.ttinclude @@ -1259,7 +1259,7 @@ public abstract class ODataClientTemplate : TemplateBase internal abstract void WriteParameterNullCheckForStaticCreateMethod(string parameterName); internal abstract void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName); internal abstract void WriteMethodEndForStaticCreateMethod(string instanceName); - internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged); + internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType); internal abstract void WriteINotifyPropertyChangedImplementation(); internal abstract void WriteClassEndForStructuredType(); internal abstract void WriteNamespaceEnd(); @@ -2440,7 +2440,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = propertyName, FixedPropertyName = GetFixedName(propertyName), PrivatePropertyName = "_" + propertyName, - PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context) + PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context), + IsOpenTypeProperty = false }; }).ToList(); @@ -2453,7 +2454,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = this.context.DynamicPropertiesCollectionName, FixedPropertyName = GetFixedName(this.context.DynamicPropertiesCollectionName), PrivatePropertyName = "_" + Utils.CamelCase(this.context.DynamicPropertiesCollectionName), - PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName) + PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName), + IsOpenTypeProperty = true }); } @@ -2472,7 +2474,8 @@ public abstract class ODataClientTemplate : TemplateBase propertyInfo.FixedPropertyName, privatePropertyName, propertyInfo.PropertyInitializationValue, - useDataServiceCollection); + useDataServiceCollection, + propertyInfo.IsOpenTypeProperty); } } @@ -4065,13 +4068,22 @@ namespace <#= fullNamespace #> <#+ } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { #> /// /// There are no comments for Property <#= propertyName #> in the schema. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + +<#+ + if (isOpenType) + { +#> + [global::Microsoft.OData.Client.ContainerProperty] +<#+ + } +#> <#+ if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) { @@ -5110,13 +5122,21 @@ Namespace <#= fullNamespace #> <#+ } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { #> ''' '''There are no comments for Property <#= propertyName #> in the schema. ''' ")> _ +<#+ + if (isOpenType) + { +#> + _ +<#+ + } +#> <#+ if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) { diff --git a/src/Unchase.OData.ConnectedService/Templates/ODataT4CodeGenerator.ttinclude b/src/Unchase.OData.ConnectedService/Templates/ODataT4CodeGenerator.ttinclude index d3fda9e..0b425bc 100644 --- a/src/Unchase.OData.ConnectedService/Templates/ODataT4CodeGenerator.ttinclude +++ b/src/Unchase.OData.ConnectedService/Templates/ODataT4CodeGenerator.ttinclude @@ -1259,7 +1259,7 @@ public abstract class ODataClientTemplate : TemplateBase internal abstract void WriteParameterNullCheckForStaticCreateMethod(string parameterName); internal abstract void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName); internal abstract void WriteMethodEndForStaticCreateMethod(string instanceName); - internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged); + internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType); internal abstract void WriteINotifyPropertyChangedImplementation(); internal abstract void WriteClassEndForStructuredType(); internal abstract void WriteNamespaceEnd(); @@ -2440,7 +2440,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = propertyName, FixedPropertyName = GetFixedName(propertyName), PrivatePropertyName = "_" + propertyName, - PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context) + PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context), + IsOpenTypeProperty = false }; }).ToList(); @@ -2453,7 +2454,8 @@ public abstract class ODataClientTemplate : TemplateBase PropertyName = this.context.DynamicPropertiesCollectionName, FixedPropertyName = GetFixedName(this.context.DynamicPropertiesCollectionName), PrivatePropertyName = "_" + Utils.CamelCase(this.context.DynamicPropertiesCollectionName), - PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName) + PropertyInitializationValue = string.Format(this.DictionaryConstructor, this.StringTypeName, this.ObjectTypeName), + IsOpenTypeProperty = true }); } @@ -2472,7 +2474,8 @@ public abstract class ODataClientTemplate : TemplateBase propertyInfo.FixedPropertyName, privatePropertyName, propertyInfo.PropertyInitializationValue, - useDataServiceCollection); + useDataServiceCollection, + propertyInfo.IsOpenTypeProperty); } } @@ -4065,13 +4068,21 @@ namespace <#= fullNamespace #> <#+ } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { #> /// /// There are no comments for Property <#= propertyName #> in the schema. /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] +<#+ + if (isOpenType) + { +#> + [global::Microsoft.OData.Client.ContainerProperty] +<#+ + } +#> <#+ if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) { @@ -5110,13 +5121,21 @@ Namespace <#= fullNamespace #> <#+ } - internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged, bool isOpenType) { #> ''' '''There are no comments for Property <#= propertyName #> in the schema. ''' ")> _ +<#+ + if (isOpenType) + { +#> + _ +<#+ + } +#> <#+ if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) {