Skip to content

Commit

Permalink
Fix identifier mapping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Winterstein authored and Greg Winterstein committed Jun 6, 2023
1 parent 1ea61b8 commit 79daad1
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,14 @@ public abstract class ODataClientTemplate : TemplateBase
{
var customizedPropertyName = customizePropertyName(property.Name);
var renamedPropertyName = uniqueIdentifierService.GetUniqueIdentifier(customizedPropertyName);
IdentifierMappings.Add(property.Name, renamedPropertyName);
if (IdentifierMappings.ContainsKey(property.Name))
{
IdentifierMappings[property.Name] = renamedPropertyName;
}
else
{
IdentifierMappings.Add(property.Name, renamedPropertyName);
}
}
}

Expand All @@ -2812,13 +2819,20 @@ public abstract class ODataClientTemplate : TemplateBase
Func<string, string> customizePropertyName = (name) => { return this.context.EnableNamingAlias ? Customization.CustomizeNaming(name) : name; };
var codeDomProvider = (this.context.TargetLanguage == LanguageOption.CSharp ? CSharpProvider : VBProvider);
var propertiesToRename = structuredType.DeclaredProperties.Where(prop => !codeDomProvider.IsValidIdentifier(prop.Name)
|| !char.IsUpper(prop.Name.First()));
&& !LanguageKeywords.Contains(prop.Name));

foreach (var property in propertiesToRename)
{
var customizedPropertyName = customizePropertyName(property.Name);
var validName = GetValidIdentifier(customizedPropertyName);
if (!IdentifierMappings.ContainsKey(customizedPropertyName))
if (IdentifierMappings.ContainsKey(property.Name))
{
if (!codeDomProvider.IsValidIdentifier(IdentifierMappings[property.Name]))
{
IdentifierMappings[property.Name] = validName;
}
}
else
{
IdentifierMappings.Add(property.Name, validName);
}
Expand Down Expand Up @@ -4960,7 +4974,7 @@ namespace <#= fullNamespace #>
<#+
}
#>
public virtual <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeNameWithSingleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>)
public virtual <#= hideBaseMethod ? $"{this.OverloadsModifier} " : string.Empty #><#= isReturnEntity ? returnTypeNameWithSingleSuffix : string.Format(CultureInfo.InvariantCulture, this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>)
{
global::System.Uri requestUri;
Context.TryGetUri(this, out requestUri);
Expand Down

0 comments on commit 79daad1

Please sign in to comment.