@@ -205,6 +205,22 @@ public static string GetSanitizedPropertyName(this OdcmProperty property)
205205 }
206206
207207 public static string GetSanitizedPropertyName ( this string property , string prefix = null )
208+ {
209+ return GetSanitizedPropertyName ( property , null , prefix ) ;
210+ }
211+
212+ /// <summary>
213+ /// Sanitizes a property name for the following conditions:
214+ /// 1) a property has the same name as a C# keyword. Prefix @ to the property name to make it valid.
215+ /// 2) a property has the same name as the class. First we'll try to change the property name to the
216+ /// return type name. If the return type name is the same as the class name, then we'll append
217+ /// "Property" to the property name.
218+ /// </summary>
219+ /// <param name="property">The string that called this extension.</param>
220+ /// <param name="odcmProperty">An OdcmProperty. Use the property that you want to sanitize.</param>
221+ /// <param name="prefix">The prefix to use on this property.</param>
222+ /// <returns></returns>
223+ public static string GetSanitizedPropertyName ( this string property , OdcmProperty odcmProperty , string prefix = null )
208224 {
209225 if ( GetReservedNames ( ) . Contains ( property ) )
210226 {
@@ -213,6 +229,22 @@ public static string GetSanitizedPropertyName(this string property, string prefi
213229 return string . Concat ( reservedPrefix , property . ToUpperFirstChar ( ) ) ;
214230 }
215231
232+ // Check whether the propertyObject is null (means they called the extension from a string).
233+ // Check whether the property name is the same as the class name.
234+ // Only constructor members may be named the same as the class name.
235+ if ( odcmProperty != null && property == odcmProperty . Class . Name . ToUpperFirstChar ( ) )
236+ {
237+ // Check whether the property type is the same as the class name.
238+ if ( odcmProperty . Projection . Type . Name . ToUpperFirstChar ( ) == odcmProperty . Class . Name . ToUpperFirstChar ( ) )
239+ {
240+ // Name the property: {metadataName} + "Property"
241+ return string . Concat ( property , "Property" ) ;
242+ }
243+
244+ // Name the property by its type. Sanitize it in case the type is a reserved name.
245+ return odcmProperty . Projection . Type . Name . ToUpperFirstChar ( ) . GetSanitizedPropertyName ( ) ;
246+ }
247+
216248 return property ;
217249 }
218250
0 commit comments