77using System . Threading . Tasks ;
88using Microsoft . CodeAnalysis ;
99using Microsoft . CodeAnalysis . CSharp ;
10+ using Microsoft . CodeAnalysis . CSharp . Formatting ;
1011using Microsoft . CodeAnalysis . CSharp . Scripting ;
1112using Microsoft . CodeAnalysis . CSharp . Syntax ;
1213using Microsoft . CodeAnalysis . Formatting ;
14+ using Microsoft . CodeAnalysis . Options ;
1315using Microsoft . CodeAnalysis . Scripting ;
1416using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
1517
@@ -46,11 +48,8 @@ public static Task<T> DeserializeAsync<T>(
4648 => CSharpScript . EvaluateAsync < T > ( script ,
4749 ScriptOptions . Default . WithReferences (
4850 typeof ( T ) . GetTypeInfo ( ) . Assembly ,
49- typeof ( List < > ) . GetTypeInfo ( ) . Assembly
50- #if ! NET46
51- , Assembly . Load ( new AssemblyName ( "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" ) )
52- #endif
53- )
51+ typeof ( List < > ) . GetTypeInfo ( ) . Assembly ,
52+ Assembly . Load ( new AssemblyName ( "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" ) ) )
5453 . AddReferences ( typeof ( CSScriptSerializer ) . GetTypeInfo ( )
5554 . Assembly . GetReferencedAssemblies ( )
5655 . Select ( Assembly . Load ) )
@@ -61,14 +60,16 @@ public static Task<T> DeserializeAsync<T>(
6160 typeof ( List < > ) . GetTypeInfo ( ) . Namespace )
6261 . AddImports ( imports ) ) ;
6362
64- public static string Serialize ( object obj )
63+ public static string Serialize ( object obj , Func < OptionSet , OptionSet > applyFormattingOptions = null )
6564 {
6665 using ( var workspace = new AdhocWorkspace ( ) )
6766 {
6867 return Formatter . Format (
6968 GetCompilationUnitExpression ( obj ) ,
7069 workspace ,
71- workspace . Options )
70+ applyFormattingOptions == null
71+ ? workspace . Options
72+ : applyFormattingOptions ( workspace . Options ) )
7273 . ToFullString ( ) ;
7374 }
7475 }
0 commit comments