@@ -234,6 +234,20 @@ private static void ProcessProperties(Class @class, IEnumerable<Property> proper
234
234
{
235
235
foreach ( Property property in properties )
236
236
{
237
+ // Look at the getter/setter names and figure out the proper casing for the
238
+ // property name.
239
+ if ( property . GetMethod != null || property . SetMethod != null )
240
+ {
241
+ var casing = GetPropertyNameCasing ( property ) ;
242
+ var proposedName = GetNameWithCasing ( property . Name , casing ) ;
243
+
244
+ // Check if there are any types in the namespace or properties in the class
245
+ // that can conflict with the proposed name.
246
+ if ( @class . FindType < Declaration > ( proposedName ) == null &&
247
+ @class . Properties . Find ( f => f . Name == proposedName ) == null )
248
+ property . Name = proposedName ;
249
+ }
250
+
237
251
ProcessOverridden ( @class , property ) ;
238
252
239
253
if ( ! property . HasGetter )
@@ -262,6 +276,39 @@ private static void ProcessProperties(Class @class, IEnumerable<Property> proper
262
276
}
263
277
}
264
278
279
+ private static string GetNameWithCasing ( string name , RenameCasePattern pattern )
280
+ {
281
+ if ( string . IsNullOrEmpty ( name ) )
282
+ return name ;
283
+
284
+ var firstChar = pattern switch
285
+ {
286
+ RenameCasePattern . UpperCamelCase => char . ToUpperInvariant ( name [ 0 ] ) ,
287
+ RenameCasePattern . LowerCamelCase => char . ToLowerInvariant ( name [ 0 ] ) ,
288
+ _ => throw new ArgumentOutOfRangeException ( nameof ( pattern ) , pattern , null )
289
+ } ;
290
+
291
+ return string . Concat ( firstChar , name . Substring ( 1 ) ) ;
292
+ }
293
+
294
+ private static RenameCasePattern GetPropertyNameCasing ( Property property )
295
+ {
296
+ RenameCasePattern GetCasePattern ( char c ) =>
297
+ char . IsUpper ( c ) ? RenameCasePattern . UpperCamelCase : RenameCasePattern . LowerCamelCase ;
298
+
299
+ if ( property . GetMethod != null )
300
+ {
301
+ // Prefer the casing of the getter to handle cases like this:
302
+ // void prop();
303
+ // bool setProp();
304
+ var getterName = GetPropertyName ( property . GetMethod . Name ) ;
305
+ return GetCasePattern ( getterName [ 0 ] ) ;
306
+ }
307
+
308
+ var setterName = GetPropertyName ( property . SetMethod . Name ) ;
309
+ return GetCasePattern ( setterName [ 0 ] ) ;
310
+ }
311
+
265
312
private static void ProcessOverridden ( Class @class , Property property )
266
313
{
267
314
if ( ! property . IsOverride )
0 commit comments