@@ -85,7 +85,7 @@ private static string TransformCode(string nswagCode)
8585 var cleaned = line
8686 . Replace ( "partial class" , "class" )
8787 . Replace ( "System.Collections.Generic." , null )
88- . Replace ( "System.Runtime.Serialization." , null )
88+ . Replace ( "System.Runtime.Serialization." , null )
8989 . Replace ( "System.ComponentModel.DataAnnotations." , null ) ;
9090
9191 builder . AppendLine ( cleaned ) ;
@@ -99,7 +99,7 @@ private static string TransformCode(string nswagCode)
9999 /// </summary>
100100 /// <param name="code">源代码</param>
101101 /// <returns></returns>
102- private static string Pretty ( string code )
102+ private static string ? Pretty ( string ? code )
103103 {
104104 if ( code == null )
105105 {
@@ -115,12 +115,12 @@ private static string Pretty(string code)
115115 var cTab = tab ;
116116 if ( line == "{" )
117117 {
118- tab = tab + 1 ;
118+ tab ++ ;
119119 }
120120 else if ( line == "}" )
121121 {
122122 cTab = tab - 1 ;
123- tab = tab - 1 ;
123+ tab -- ;
124124 }
125125
126126 var isEndMethod = line . EndsWith ( ");" ) ;
@@ -142,7 +142,7 @@ private static string Pretty(string code)
142142 /// </summary>
143143 /// <param name="code">源代码</param>
144144 /// <returns></returns>
145- private static string Compact ( string code )
145+ private static string ? Compact ( string ? code )
146146 {
147147 if ( code == null )
148148 {
@@ -166,18 +166,24 @@ private static string Compact(string code)
166166 /// </summary>
167167 /// <param name="code">源代码</param>
168168 /// <returns></returns>
169- private static IEnumerable < string > GetLines ( string code )
169+ private static IEnumerable < string > GetLines ( string ? code )
170170 {
171171 if ( code == null )
172172 {
173173 yield break ;
174174 }
175175
176- using ( var reader = new StringReader ( code ) )
176+ using var reader = new StringReader ( code ) ;
177+ while ( true )
177178 {
178- while ( reader . Peek ( ) >= 0 )
179+ var line = reader . ReadLine ( ) ;
180+ if ( line == null )
179181 {
180- yield return reader . ReadLine ( ) ;
182+ yield break ;
183+ }
184+ else
185+ {
186+ yield return line ;
181187 }
182188 }
183189 }
0 commit comments