From 8a646780b85873a1c9295c97b51264a0fcbc92c8 Mon Sep 17 00:00:00 2001 From: Greg Winterstein Date: Wed, 14 Jun 2023 14:29:05 -0700 Subject: [PATCH] Fix conflicting property name detection, minimize changes --- .../Templates/ODataT4CodeGenerator.cs | 16 ++++++++-------- .../Templates/ODataT4CodeGenerator.ttinclude | 13 ++++++------- .../CodeGenReferences/DupNames.cs | 1 - .../CodeGenReferences/DupNamesDSC.vb | 1 - .../DupNamesWithCamelCaseDSC.cs | 12 ++++++------ .../CodeGenReferences/KeywordsAsNames.cs | 6 +++--- .../CodeGenReferences/PrefixConflict.cs | 1 - .../CodeGenReferences/PrefixConflictDSC.vb | 1 - 8 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs b/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs index e9e96ef5..18f34a06 100644 --- a/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs +++ b/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs @@ -10,6 +10,7 @@ namespace Microsoft.OData.CodeGen.Templates { using System; + using System.CodeDom.Compiler; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -18,6 +19,7 @@ namespace Microsoft.OData.CodeGen.Templates using System.Net; using System.Security; using System.Text; + using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; using Microsoft.OData.Edm.Csdl; @@ -29,8 +31,6 @@ namespace Microsoft.OData.CodeGen.Templates using Microsoft.OData.CodeGen.FileHandling; using Microsoft.OData.CodeGen.Logging; using Microsoft.OData.CodeGen.Common; - using System.CodeDom.Compiler; - using System.Text.RegularExpressions; /// /// Class to produce the template output @@ -2923,7 +2923,7 @@ internal void SetPropertyIdentifierMappingsIfBaseConflicts(IEdmStructuredType st baseProperties = BaseClassProperties.Select(prop => prop.ToUpperInvariant()); } - var propertiesToRename = structuredType.DeclaredProperties.Where(prop => baseProperties.Contains((isLanguageCaseSensitive ? prop.Name : prop.Name.ToUpperInvariant()))); + var propertiesToRename = structuredType.DeclaredProperties.Where(prop => baseProperties.Contains((isLanguageCaseSensitive ? customizePropertyName(prop.Name) : prop.Name.ToUpperInvariant()))); UniqueIdentifierService uniqueIdentifierService = new UniqueIdentifierService(BaseClassProperties, isLanguageCaseSensitive); @@ -4577,8 +4577,8 @@ internal override void WriteConstructorForSingleType(string singleTypeName, stri this.Write(this.ToStringHelper.ToStringWithCulture(singleTypeName)); this.Write("(global::Microsoft.OData.Client.DataServiceContext context, string path)\r\n " + - " : base(context, path) { }\r\n\r\n /// \r\n /// Initialize " + - "a new "); + " : base(context, path) {}\r\n\r\n /// \r\n /// Initialize a" + + " new "); this.Write(this.ToStringHelper.ToStringWithCulture(singleTypeName)); @@ -4587,8 +4587,8 @@ internal override void WriteConstructorForSingleType(string singleTypeName, stri this.Write(this.ToStringHelper.ToStringWithCulture(singleTypeName)); this.Write("(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isC" + - "omposable)\r\n : base(context, path, isComposable) { }\r\n\r\n /// <" + - "summary>\r\n /// Initialize a new "); + "omposable)\r\n : base(context, path, isComposable) {}\r\n\r\n /// \r\n /// Initialize a new "); this.Write(this.ToStringHelper.ToStringWithCulture(singleTypeName)); @@ -4600,7 +4600,7 @@ internal override void WriteConstructorForSingleType(string singleTypeName, stri this.Write(this.ToStringHelper.ToStringWithCulture(baseTypeName)); -this.Write(" query)\r\n : base(query) { }\r\n\r\n"); +this.Write(" query)\r\n : base(query) {}\r\n\r\n"); } diff --git a/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.ttinclude b/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.ttinclude index b7dcae36..0fa5a83e 100644 --- a/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.ttinclude +++ b/src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.ttinclude @@ -18,6 +18,7 @@ <#@ Assembly Name="System.Windows.Forms.dll" #> <#@ Assembly Name="Microsoft.OData.Edm.dll" #> <#@ Import Namespace="System" #> +<#@ Import Namespace= "System.CodeDom.Compiler"#> <#@ Import Namespace="System.Collections.Generic" #> <#@ Import Namespace="System.Diagnostics" #> <#@ Import Namespace="System.Globalization" #> @@ -26,6 +27,7 @@ <#@ Import Namespace="System.Net"#> <#@ Import Namespace="System.Security"#> <#@ Import Namespace="System.Text"#> +<#@ Import Namespace= "System.Text.RegularExpressions"#> <#@ Import Namespace="System.Xml"#> <#@ Import Namespace="System.Xml.Linq" #> <#@ Import Namespace="Microsoft.OData.Edm.Csdl" #> @@ -37,8 +39,6 @@ <#@ Import Namespace="Microsoft.OData.CodeGen.FileHandling" #> <#@ Import Namespace="Microsoft.OData.CodeGen.Logging" #> <#@ Import Namespace= "Microsoft.OData.CodeGen.Common"#> -<#@ Import Namespace= "System.CodeDom.Compiler"#> -<#@ Import Namespace= "System.Text.RegularExpressions"#> <#@include file="ODataT4CodeGenFilesManager.ttinclude" #><# CodeGenerationContext context; @@ -2781,7 +2781,7 @@ public abstract class ODataClientTemplate : TemplateBase baseProperties = BaseClassProperties.Select(prop => prop.ToUpperInvariant()); } - var propertiesToRename = structuredType.DeclaredProperties.Where(prop => baseProperties.Contains((isLanguageCaseSensitive ? prop.Name : prop.Name.ToUpperInvariant()))); + var propertiesToRename = structuredType.DeclaredProperties.Where(prop => baseProperties.Contains((isLanguageCaseSensitive ? customizePropertyName(prop.Name) : prop.Name.ToUpperInvariant()))); UniqueIdentifierService uniqueIdentifierService = new UniqueIdentifierService(BaseClassProperties, isLanguageCaseSensitive); @@ -4352,19 +4352,19 @@ namespace <#= fullNamespace #> /// Initialize a new <#= singleTypeName #> object. /// public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) - : base(context, path) { } + : base(context, path) {} /// /// Initialize a new <#= singleTypeName #> object. /// public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) - : base(context, path, isComposable) { } + : base(context, path, isComposable) {} /// /// Initialize a new <#= singleTypeName #> object. /// public <#= singleTypeName #>(<#= baseTypeName #> query) - : base(query) { } + : base(query) {} <#+ } @@ -4794,7 +4794,6 @@ namespace <#= fullNamespace #> WriteRequiredAttribute($"{propertyOptions.PropertyName} is required."); } #> - <#+ if (!string.IsNullOrEmpty(propertyOptions.PropertyAttribute)) { diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/DupNames.cs b/test/ODataConnectedService.Tests/CodeGenReferences/DupNames.cs index ff8c8b05..59d53704 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/DupNames.cs +++ b/test/ODataConnectedService.Tests/CodeGenReferences/DupNames.cs @@ -24,7 +24,6 @@ public EntityContainer(global::System.Uri serviceRoot) : this(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) { } - /// /// Initialize a new EntityContainer object. /// diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesDSC.vb b/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesDSC.vb index c52c7d56..943058ed 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesDSC.vb +++ b/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesDSC.vb @@ -26,7 +26,6 @@ Namespace DupNames.DSC Public Sub New(ByVal serviceRoot As Global.System.Uri) Me.New(serviceRoot, Global.Microsoft.OData.Client.ODataProtocolVersion.V4) End Sub - ''' ''' Initialize a new EntityContainer object. ''' diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesWithCamelCaseDSC.cs b/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesWithCamelCaseDSC.cs index cf9b5663..234cacc1 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesWithCamelCaseDSC.cs +++ b/test/ODataConnectedService.Tests/CodeGenReferences/DupNamesWithCamelCaseDSC.cs @@ -226,19 +226,19 @@ public partial class DupWithTypeNameSingle : global::Microsoft.OData.Client.Data /// Initialize a new DupWithTypeNameSingle object. /// public DupWithTypeNameSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) - : base(context, path) { } + : base(context, path) {} /// /// Initialize a new DupWithTypeNameSingle object. /// public DupWithTypeNameSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) - : base(context, path, isComposable) { } + : base(context, path, isComposable) {} /// /// Initialize a new DupWithTypeNameSingle object. /// public DupWithTypeNameSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) - : base(query) { } + : base(query) {} /// /// There are no comments for DupPropertyName1 in the schema. @@ -653,19 +653,19 @@ public partial class DupWithTypeName1Single : global::Microsoft.OData.Client.Dat /// Initialize a new DupWithTypeName1Single object. /// public DupWithTypeName1Single(global::Microsoft.OData.Client.DataServiceContext context, string path) - : base(context, path) { } + : base(context, path) {} /// /// Initialize a new DupWithTypeName1Single object. /// public DupWithTypeName1Single(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) - : base(context, path, isComposable) { } + : base(context, path, isComposable) {} /// /// Initialize a new DupWithTypeName1Single object. /// public DupWithTypeName1Single(global::Microsoft.OData.Client.DataServiceQuerySingle query) - : base(query) { } + : base(query) {} } /// diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/KeywordsAsNames.cs b/test/ODataConnectedService.Tests/CodeGenReferences/KeywordsAsNames.cs index 26a46505..4a38d982 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/KeywordsAsNames.cs +++ b/test/ODataConnectedService.Tests/CodeGenReferences/KeywordsAsNames.cs @@ -169,19 +169,19 @@ public partial class eventSingle : global::Microsoft.OData.Client.DataServiceQue /// Initialize a new eventSingle object. /// public eventSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) - : base(context, path) { } + : base(context, path) {} /// /// Initialize a new eventSingle object. /// public eventSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) - : base(context, path, isComposable) { } + : base(context, path, isComposable) {} /// /// Initialize a new eventSingle object. /// public eventSingle(global::Microsoft.OData.Client.DataServiceQuerySingle<@event> query) - : base(query) { } + : base(query) {} /// /// There are no comments for event1 in the schema. diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflict.cs b/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflict.cs index b4218895..f8c5bbd4 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflict.cs +++ b/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflict.cs @@ -24,7 +24,6 @@ public EntityContainer(global::System.Uri serviceRoot) : this(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) { } - /// /// Initialize a new EntityContainer object. /// diff --git a/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflictDSC.vb b/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflictDSC.vb index e3520f83..0fd93e7c 100644 --- a/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflictDSC.vb +++ b/test/ODataConnectedService.Tests/CodeGenReferences/PrefixConflictDSC.vb @@ -26,7 +26,6 @@ Namespace PrefixConflict.DSC Public Sub New(ByVal serviceRoot As Global.System.Uri) Me.New(serviceRoot, Global.Microsoft.OData.Client.ODataProtocolVersion.V4) End Sub - ''' ''' Initialize a new EntityContainer object. '''