@@ -19,9 +19,11 @@ private class PropertyGenerator
19
19
private readonly List < Method > setters = new List < Method > ( ) ;
20
20
private readonly List < Method > setMethods = new List < Method > ( ) ;
21
21
private readonly List < Method > nonSetters = new List < Method > ( ) ;
22
+ private bool useHeuristics = true ;
22
23
23
- public PropertyGenerator ( Class @class )
24
+ public PropertyGenerator ( Class @class , bool useHeuristics )
24
25
{
26
+ this . useHeuristics = useHeuristics ;
25
27
foreach ( var method in @class . Methods . Where (
26
28
m => ! m . IsConstructor && ! m . IsDestructor && ! m . IsOperator && m . IsGenerated ) )
27
29
DistributeMethod ( method ) ;
@@ -266,16 +268,21 @@ private void DistributeMethod(Method method)
266
268
}
267
269
}
268
270
269
- private static bool IsGetter ( Method method )
271
+ private bool IsGetter ( Method method )
270
272
{
271
273
if ( method . IsDestructor ||
272
274
( method . OriginalReturnType . Type . IsPrimitiveType ( PrimitiveType . Void ) ) ||
273
275
method . Parameters . Any ( p => p . Kind != ParameterKind . IndirectReturnType ) )
274
276
return false ;
275
277
var firstWord = GetFirstWord ( method . Name ) ;
276
- return ( firstWord . Length < method . Name . Length &&
277
- Match ( firstWord , new [ ] { "get" , "is" , "has" } ) ) ||
278
- ( ! Match ( firstWord , new [ ] { "to" , "new" } ) && ! verbs . Contains ( firstWord ) ) ;
278
+
279
+ if ( firstWord . Length < method . Name . Length && Match ( firstWord , new [ ] { "get" , "is" , "has" } ) )
280
+ return true ;
281
+
282
+ if ( useHeuristics && ! Match ( firstWord , new [ ] { "to" , "new" } ) && ! verbs . Contains ( firstWord ) )
283
+ return true ;
284
+
285
+ return false ;
279
286
}
280
287
281
288
private static bool Match ( string prefix , IEnumerable < string > prefixes )
@@ -354,7 +361,7 @@ public GetterSetterToPropertyPass()
354
361
public override bool VisitClassDecl ( Class @class )
355
362
{
356
363
if ( base . VisitClassDecl ( @class ) )
357
- new PropertyGenerator ( @class ) . GenerateProperties ( ) ;
364
+ new PropertyGenerator ( @class , Options . UsePropertyDetectionHeuristics ) . GenerateProperties ( ) ;
358
365
return false ;
359
366
}
360
367
}
0 commit comments