Skip to content

Commit 62156a2

Browse files
authored
Update GetSanitizedPropertyName method
Now allows GetSanitizedPropertyName to accept an additional parameter, suffix, so that an additional string may be concatenated onto the end of the Property. Updated method logic to look for and concatenate suffix when specified.
1 parent bca4cc4 commit 62156a2

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,19 @@ public static string GetSanitizedLongDescription(this OdcmProperty property)
222222
return null;
223223
}
224224

225-
public static string GetSanitizedPropertyName(this OdcmProperty property)
225+
public static string GetSanitizedPropertyName(this OdcmProperty property, string prefix = null, string suffix = null)
226226
{
227-
return GetSanitizedPropertyName(property.Name);
227+
return GetSanitizedPropertyName(property.Name, prefix, suffix);
228228
}
229229

230230
public static string GetSanitizedClassName(this OdcmClass odcmClass)
231231
{
232232
return GetSanitizedClassName(odcmClass.Name, odcmClass);
233233
}
234234

235-
public static string GetSanitizedPropertyName(this string property, string prefix = null)
235+
public static string GetSanitizedPropertyName(this string property, string prefix = null, string suffix = null)
236236
{
237-
return GetSanitizedPropertyName(property, null, prefix);
237+
return GetSanitizedPropertyName(property, null, prefix, suffix);
238238
}
239239

240240
/// <summary>
@@ -248,34 +248,37 @@ public static string GetSanitizedPropertyName(this string property, string prefi
248248
/// <param name="odcmProperty">An OdcmProperty. Use the property that you want to sanitize.</param>
249249
/// <param name="prefix">The prefix to use on this property.</param>
250250
/// <returns></returns>
251-
public static string GetSanitizedPropertyName(this string property, OdcmProperty odcmProperty, string prefix = null)
251+
public static string GetSanitizedPropertyName(this string property, OdcmProperty odcmProperty, string prefix = null, string suffix = null)
252252
{
253+
string result = property;
253254
if (GetReservedNames().Contains(property))
254255
{
255256
var reservedPrefix = string.IsNullOrEmpty(prefix) ? DefaultReservedPrefix : prefix;
256257

257258
logger.Info("Property \"{0}\" is a reserved word in .NET. Converting to \"{1}{0}\"", property.ToUpperFirstChar(), reservedPrefix);
258-
return string.Concat(reservedPrefix, property.ToUpperFirstChar());
259+
result = string.Concat(reservedPrefix, property.ToUpperFirstChar());
259260
}
260-
261-
// Check whether the propertyObject is null (means they called the extension from a string).
262-
// Check whether the property name is the same as the class name.
263-
// Only constructor members may be named the same as the class name.
264-
if (odcmProperty != null && property == odcmProperty.Class.Name.ToUpperFirstChar())
261+
else if (odcmProperty != null && property == odcmProperty.Class.Name.ToUpperFirstChar())
265262
{
263+
// Check whether the propertyObject is null (means they called the extension from a string).
264+
// Check whether the property name is the same as the class name.
265+
// Only constructor members may be named the same as the class name.
266+
266267
// Check whether the property type is the same as the class name.
267268
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Class.Name.ToUpperFirstChar())
268269
{
269270
// Name the property: {metadataName} + "Property"
270271
logger.Info("Property type \"{0}\" has the same name as the class. Converting to \"{0}Property\"", property);
271-
return string.Concat(property, "Property");
272+
result = string.Concat(property, "Property");
273+
}
274+
else
275+
{
276+
// Name the property by its type. Sanitize it in case the type is a reserved name.
277+
result = odcmProperty.Projection.Type.Name.ToUpperFirstChar().GetSanitizedPropertyName();
272278
}
273-
274-
// Name the property by its type. Sanitize it in case the type is a reserved name.
275-
return odcmProperty.Projection.Type.Name.ToUpperFirstChar().GetSanitizedPropertyName();
276279
}
277280

278-
return property;
281+
return result+suffix;
279282
}
280283

281284
public static string GetSanitizedClassName(this string className, OdcmClass odcmClass)

0 commit comments

Comments
 (0)