1+ using System ;
12using System . Linq ;
23using System . Text . RegularExpressions ;
34using Microsoft . CodeAnalysis ;
45using Microsoft . CodeAnalysis . CSharp ;
56using Microsoft . CodeAnalysis . CSharp . Syntax ;
7+ using PlantUmlClassDiagramGenerator . Attributes ;
68
79namespace PlantUmlClassDiagramGenerator . Library . ClassDiagramGenerator ;
810
@@ -32,33 +34,59 @@ public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
3234 || typeIgnoringNullable is PredefinedTypeSyntax
3335 || isTypeParameterProp )
3436 {
35- var modifiers = GetMemberModifiersText ( node . Modifiers ,
36- isInterfaceMember : node . Parent . IsKind ( SyntaxKind . InterfaceDeclaration ) ) ;
37- var name = node . Identifier . ToString ( ) ;
38- //Property does not have an accessor is an expression-bodied property. (get only)
39- var accessorStr = "<<get>>" ;
40- if ( node . AccessorList != null )
41- {
42- var accessor = node . AccessorList . Accessors
43- . Where ( x => ! x . Modifiers . Select ( y => y . Kind ( ) ) . Contains ( SyntaxKind . PrivateKeyword ) )
44- . Select ( x => $ "<<{ ( x . Modifiers . ToString ( ) == "" ? "" : ( x . Modifiers . ToString ( ) + " " ) ) } { x . Keyword } >>") ;
45- accessorStr = string . Join ( " " , accessor ) ;
46- }
47- var useLiteralInit = node . Initializer ? . Value ? . Kind ( ) . ToString ( ) . EndsWith ( "LiteralExpression" ) ?? false ;
48- var initValue = useLiteralInit
49- ? ( " = " + escapeDictionary . Aggregate ( node . Initializer . Value . ToString ( ) ,
50- ( n , e ) => Regex . Replace ( n , e . Key , e . Value ) ) )
51- : "" ;
52-
53- WriteLine ( $ "{ modifiers } { name } : { type } { accessorStr } { initValue } ") ;
37+ FillAssociatedProperty ( node , type ) ;
5438 }
5539 else
5640 {
5741 if ( type . GetType ( ) == typeof ( GenericNameSyntax ) )
5842 {
59- additionalTypeDeclarationNodes . Add ( type ) ;
60- }
61- relationships . AddAssociationFrom ( node , typeIgnoringNullable ) ;
43+ if ( this . removeSystemCollectionsAssociations )
44+ {
45+ var t = node . Type . ToString ( ) . Split ( '<' ) [ 0 ] ;
46+ if ( ! Enum . TryParse ( t , out SystemCollectionsTypes _ ) )
47+ additionalTypeDeclarationNodes . Add ( type ) ;
48+ else
49+ {
50+ FillAssociatedProperty ( node , type ) ;
51+ var s = node . Type . ToString ( ) ;
52+ relationships . AddAssociationFrom ( node , new PlantUmlAssociationAttribute ( )
53+ {
54+ Association = "o--" ,
55+ Name = s . Substring ( s . IndexOf ( '<' ) + 1 , s . LastIndexOf ( '>' ) - s . IndexOf ( '<' ) - 1 )
56+ } ) ;
57+ }
58+ }
59+ else
60+ {
61+ additionalTypeDeclarationNodes . Add ( type ) ;
62+ relationships . AddAssociationFrom ( node , typeIgnoringNullable ) ;
63+ }
64+ } else
65+ relationships . AddAssociationFrom ( node , typeIgnoringNullable ) ;
6266 }
6367 }
68+
69+ private void FillAssociatedProperty ( PropertyDeclarationSyntax node , TypeSyntax type )
70+ {
71+ var modifiers = GetMemberModifiersText ( node . Modifiers ,
72+ isInterfaceMember : node . Parent . IsKind ( SyntaxKind . InterfaceDeclaration ) ) ;
73+ var name = node . Identifier . ToString ( ) ;
74+ //Property does not have an accessor is an expression-bodied property. (get only)
75+ var accessorStr = "<<get>>" ;
76+ if ( node . AccessorList != null )
77+ {
78+ var accessor = node . AccessorList . Accessors
79+ . Where ( x => ! x . Modifiers . Select ( y => y . Kind ( ) ) . Contains ( SyntaxKind . PrivateKeyword ) )
80+ . Select ( x => $ "<<{ ( x . Modifiers . ToString ( ) == "" ? "" : ( x . Modifiers . ToString ( ) + " " ) ) } { x . Keyword } >>") ;
81+ accessorStr = string . Join ( " " , accessor ) ;
82+ }
83+
84+ var useLiteralInit = node . Initializer ? . Value ? . Kind ( ) . ToString ( ) . EndsWith ( "LiteralExpression" ) ?? false ;
85+ var initValue = useLiteralInit
86+ ? ( " = " + escapeDictionary . Aggregate ( node . Initializer . Value . ToString ( ) ,
87+ ( n , e ) => Regex . Replace ( n , e . Key , e . Value ) ) )
88+ : "" ;
89+
90+ WriteLine ( $ "{ modifiers } { name } : { type } { accessorStr } { initValue } ") ;
91+ }
6492}
0 commit comments