Skip to content

Commit 359bc2d

Browse files
author
Caitlin Bales (MSFT)
committed
Add check for class and property name collision
1 parent cd4cc85 commit 359bc2d

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Templates/Android/BaseModel.template.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public {1} {2}{3}{4} {{";
660660
propertyName.SplitCamelCase(),
661661
property.Name,
662662
propertyType,
663-
property.SanitizePropertyName().ToLowerFirstChar());
663+
property.Name.SanitizePropertyName(property).ToLowerFirstChar());
664664
}
665665
return sb.ToString();
666666
}
@@ -685,7 +685,7 @@ public {1} {2}{3}{4} {{";
685685
ParamName(p).SplitCamelCase(),
686686
ParamName(p),
687687
ParamType(p),
688-
p.SanitizePropertyName().ToLowerFirstChar()
688+
ParamName(p).SanitizePropertyName(p).ToLowerFirstChar()
689689
);
690690
}
691691
return sb.ToString();
@@ -755,7 +755,7 @@ public {1} {2}{3}{4} {{";
755755
{0} = new {2}(response, null);
756756
}}
757757
",
758-
property.SanitizePropertyName(),
758+
property.Name.SanitizePropertyName(property),
759759
BaseTypeCollectionResponse(property),
760760
TypeCollectionPage(property),
761761
property.GetTypeString());

Templates/Android/extensions/Enum.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum <#= c.Name.ToUpperFirstChar()#>
1717
/**
1818
* <#= value.Name.SplitCamelCase()#>
1919
*/
20-
<#= value.SanitizePropertyName() #>,
20+
<#= value.Name.SanitizePropertyName(c) #>,
2121
<#
2222
}
2323
#>

src/GraphODataTemplateWriter/CodeHelpers/Android/TypeHelperAndroid.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,27 @@ public static string GetToLowerFirstCharName(this OdcmProperty property)
8484
return property.Name.ToLowerFirstChar();
8585
}
8686

87-
public static string SanitizePropertyName(this OdcmObject property)
87+
public static string SanitizePropertyName(this string property, OdcmObject odcmProperty = null)
8888
{
89-
if (ReservedNames.Contains(property.Name))
89+
if (ReservedNames.Contains(property))
9090
{
91-
return ReservedPrefix + property.Name;
91+
return ReservedPrefix + property;
9292
}
9393

94-
return property.Name.Replace("@", string.Empty).Replace(".", "_");
94+
if (odcmProperty != null && property == odcmProperty.Name.ToUpperFirstChar())
95+
{
96+
// Check whether the property type is the same as the class name.
97+
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Name.ToUpperFirstChar())
98+
{
99+
// Name the property: {metadataName} + "Property"
100+
return string.Concat(property, "Property");
101+
}
102+
103+
// Name the property by its type. Sanitize it in case the type is a reserved name.
104+
return odcmProperty.Projection.Type.Name.ToUpperFirstChar().SanitizePropertyName(odcmProperty);
105+
}
106+
107+
return property.Replace("@", string.Empty).Replace(".", "_");
95108
}
96109

97110
public static string GetToLowerImport(this OdcmProperty property)

0 commit comments

Comments
 (0)