@@ -27,50 +27,7 @@ public override void VisitRecordDeclaration(RecordDeclarationSyntax node)
27
27
28
28
base . VisitRecordDeclaration ( node ) ;
29
29
30
- // Check for parts that are generated and not declared by the author
31
- var symbol = semanticModel . GetDeclaredSymbol ( node ) ;
32
- if ( symbol != null )
33
- {
34
- foreach ( var constructor in symbol . Constructors )
35
- {
36
- var constructorDescription = new ConstructorDescription ( symbol . Name ) ;
37
-
38
- foreach ( var parameter in constructor . Parameters )
39
- {
40
- var parameterDescription = new ParameterDescription ( parameter . Type . ToDisplayString ( ) , parameter . Name ) ;
41
- constructorDescription . Parameters . Add ( parameterDescription ) ;
42
-
43
- parameterDescription . HasDefaultValue = parameter . HasExplicitDefaultValue ;
44
- }
45
-
46
- if ( ! this . currentType . Constructors . Any ( c => c . Parameters . Select ( p => p . Type ) . SequenceEqual ( constructorDescription . Parameters . Select ( p => p . Type ) ) ) )
47
- {
48
- this . currentType . AddMember ( constructorDescription ) ;
49
-
50
- constructorDescription . Modifiers |= constructor . IsSealed ? Modifier . Sealed : 0 ;
51
-
52
- this . EnsureMemberDefaultAccessModifier ( constructorDescription ) ;
53
- }
54
- }
55
-
56
- foreach ( var member in symbol . GetMembers ( ) )
57
- {
58
- if ( member is IPropertySymbol property )
59
- {
60
- if ( this . currentType . Properties . Any ( p => p . Name == property . Name ) )
61
- {
62
- continue ;
63
- }
64
-
65
- var propertyDescription = new PropertyDescription ( property . Type . ToDisplayString ( ) , property . Name ) ;
66
- this . currentType . AddMember ( propertyDescription ) ;
67
-
68
- propertyDescription . Modifiers |= property . IsReadOnly ? Modifier . Readonly : 0 ;
69
-
70
- this . EnsureMemberDefaultAccessModifier ( propertyDescription ) ;
71
- }
72
- }
73
- }
30
+ this . ProcessRecordSymbolInformation ( node ) ;
74
31
}
75
32
76
33
public override void VisitEnumDeclaration ( EnumDeclarationSyntax node )
@@ -347,4 +304,85 @@ private AttributeArgumentDescription CreateArgumentDescription(AttributeArgument
347
304
348
305
return new AttributeArgumentDescription ( name , typeDisplayString , value ) ;
349
306
}
307
+
308
+ private void ProcessRecordSymbolInformation ( RecordDeclarationSyntax node )
309
+ {
310
+ var symbol = semanticModel . GetDeclaredSymbol ( node ) ;
311
+ if ( symbol == null ) return ;
312
+
313
+ this . ProcessConstructors ( symbol ) ;
314
+ this . ProcessProperties ( symbol ) ;
315
+ }
316
+
317
+ private void ProcessConstructors ( INamedTypeSymbol symbol )
318
+ {
319
+ if ( this . currentType is null ) return ;
320
+
321
+ foreach ( var constructor in symbol . Constructors )
322
+ {
323
+ var constructorDescription = CreateConstructorDescription ( constructor , symbol . Name ) ;
324
+
325
+ if ( ! this . ConstructorAlreadyExists ( constructorDescription ) )
326
+ {
327
+ this . currentType . AddMember ( constructorDescription ) ;
328
+ this . EnsureMemberDefaultAccessModifier ( constructorDescription ) ;
329
+ }
330
+ }
331
+ }
332
+
333
+ private static ConstructorDescription CreateConstructorDescription ( IMethodSymbol constructor , string typeName )
334
+ {
335
+ var constructorDescription = new ConstructorDescription ( typeName ) ;
336
+
337
+ foreach ( var parameter in constructor . Parameters )
338
+ {
339
+ var parameterDescription = new ParameterDescription ( parameter . Type . ToDisplayString ( ) , parameter . Name )
340
+ {
341
+ HasDefaultValue = parameter . HasExplicitDefaultValue
342
+ } ;
343
+
344
+ constructorDescription . Parameters . Add ( parameterDescription ) ;
345
+ }
346
+
347
+ return constructorDescription ;
348
+ }
349
+
350
+ private void ProcessProperties ( INamedTypeSymbol symbol )
351
+ {
352
+ if ( this . currentType is null ) return ;
353
+
354
+ foreach ( var member in symbol . GetMembers ( ) )
355
+ {
356
+ if ( member is IPropertySymbol property && ! this . PropertyAlreadyExists ( property . Name ) )
357
+ {
358
+ var propertyDescription = this . CreatePropertyDescription ( property ) ;
359
+
360
+ this . currentType . AddMember ( propertyDescription ) ;
361
+ }
362
+ }
363
+ }
364
+
365
+ private bool ConstructorAlreadyExists ( ConstructorDescription constructorDescription )
366
+ {
367
+ return this . currentType ? . Constructors . Any ( c => c . Parameters . Select ( p => p . Type ) . SequenceEqual ( constructorDescription . Parameters . Select ( p => p . Type ) ) ) ?? false ;
368
+ }
369
+
370
+ private bool PropertyAlreadyExists ( string propertyName )
371
+ {
372
+ return this . currentType ? . Properties . Any ( p => p . Name == propertyName ) ?? false ;
373
+ }
374
+
375
+ private PropertyDescription CreatePropertyDescription ( IPropertySymbol property )
376
+ {
377
+ var modifiers = property . IsReadOnly ? Modifier . Readonly : 0 ;
378
+
379
+ var propertyDescription = new PropertyDescription ( property . Type . ToDisplayString ( ) , property . Name )
380
+ {
381
+ Modifiers = modifiers
382
+ } ;
383
+
384
+ this . EnsureMemberDefaultAccessModifier ( propertyDescription ) ;
385
+
386
+ return propertyDescription ;
387
+ }
350
388
}
0 commit comments