@@ -30,7 +30,10 @@ public Flowchart(FlowchartTitle title, FlowchartDirection? direction = null) : t
3030
3131 public Flowchart AddNode ( INode node )
3232 {
33- if ( node is Node nd && Nodes . Any ( nd . Equals ) ) return this ;
33+ if ( node is Node nd && Nodes . Any ( nd . Equals ) )
34+ {
35+ return this ;
36+ }
3437
3538 _nodes . Add ( node ) ;
3639 return this ;
@@ -60,12 +63,20 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
6063 {
6164 flowchartStringBuilder . AppendLine ( node . ToMermaidString ( indentations + 1 , indentationText ) ) ;
6265 }
63- if ( Subgraphs . Any ( ) ) flowchartStringBuilder . AppendLine ( ) ;
66+ if ( Subgraphs . Any ( ) )
67+ {
68+ flowchartStringBuilder . AppendLine ( ) ;
69+ }
70+
6471 foreach ( Subgraph subgraph in Subgraphs )
6572 {
6673 flowchartStringBuilder . AppendLine ( subgraph . ToMermaidString ( indentations + 1 , indentationText ) ) ;
6774 }
68- if ( _links . Any ( ) ) flowchartStringBuilder . AppendLine ( ) ;
75+ if ( _links . Any ( ) )
76+ {
77+ flowchartStringBuilder . AppendLine ( ) ;
78+ }
79+
6980 foreach ( Link link in _links )
7081 {
7182 flowchartStringBuilder . AppendLine ( link . ToMermaidString ( indentations + 1 , indentationText ) ) ;
@@ -75,15 +86,27 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
7586 Dictionary < NodeStyle , HashSet < NodeIdentifier > > distinctNodeStyles = [ ] ;
7687 foreach ( Node node in AllNodes )
7788 {
78- if ( node . NodeStyle is null ) continue ;
89+ if ( node . NodeStyle is null )
90+ {
91+ continue ;
92+ }
7993
8094 // Add node style declaration
81- if ( ! distinctNodeStyles . ContainsKey ( node . NodeStyle ) ) distinctNodeStyles [ node . NodeStyle ] = [ ] ;
82- distinctNodeStyles [ node . NodeStyle ] . Add ( node . Id ) ;
95+ if ( ! distinctNodeStyles . TryGetValue ( node . NodeStyle , out HashSet < NodeIdentifier > ? value ) )
96+ {
97+ value = [ ] ;
98+ distinctNodeStyles [ node . NodeStyle ] = value ;
99+ }
100+
101+ value . Add ( node . Id ) ;
83102 }
84103
85104 // Add node style declarations and assignments
86- if ( distinctNodeStyles . Any ( ) ) flowchartStringBuilder . AppendLine ( ) ;
105+ if ( distinctNodeStyles . Any ( ) )
106+ {
107+ flowchartStringBuilder . AppendLine ( ) ;
108+ }
109+
87110 foreach ( ( NodeStyle nodeStyle , HashSet < NodeIdentifier > nodeIds ) in distinctNodeStyles )
88111 {
89112 flowchartStringBuilder . AppendLine ( nodeStyle . ToMermaidString ( indentations + 1 , indentationText ) ) ;
@@ -94,20 +117,32 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
94117 Dictionary < StyleClass , HashSet < int > > distinctLinkStyles = [ ] ;
95118 foreach ( ( Link link , int index ) in AllLinks . Select ( ( l , i ) => ( l , i ) ) )
96119 {
97- if ( link . LinkStyle is null ) continue ;
120+ if ( link . LinkStyle is null )
121+ {
122+ continue ;
123+ }
98124
99125 // Add link style declaration
100- if ( ! distinctLinkStyles . ContainsKey ( link . LinkStyle ) ) distinctLinkStyles [ link . LinkStyle ] = [ ] ;
101- distinctLinkStyles [ link . LinkStyle ] . Add ( index ) ;
126+ if ( ! distinctLinkStyles . TryGetValue ( link . LinkStyle , out HashSet < int > ? value ) )
127+ {
128+ value = [ ] ;
129+ distinctLinkStyles [ link . LinkStyle ] = value ;
130+ }
131+
132+ value . Add ( index ) ;
102133 }
103134
104135 // Add link style declarations and assignments
105- if ( distinctLinkStyles . Any ( ) ) flowchartStringBuilder . AppendLine ( ) ;
136+ if ( distinctLinkStyles . Any ( ) )
137+ {
138+ flowchartStringBuilder . AppendLine ( ) ;
139+ }
140+
106141 foreach ( ( StyleClass styleClass , HashSet < int > indices ) in distinctLinkStyles )
107142 {
108143 flowchartStringBuilder . AppendLine ( $ "{ indentationText . Repeat ( indentations + 1 ) } linkStyle { string . Join ( ',' , indices ) } { styleClass . ToMermaidString ( ) } ") ;
109144 }
110145
111146 return flowchartStringBuilder . ToString ( ) ;
112147 }
113- }
148+ }
0 commit comments