@@ -31,12 +31,13 @@ public static string EmitAssemblyFromSyntax(string syntax,
31
31
}
32
32
33
33
public static Stream EmitAssemblyStreamFromSyntax ( string syntax ,
34
+ IEnumerable < KeyValuePair < string , ReportDiagnostic > > diagnosticOptions = null ,
34
35
bool enableNullable = false ,
35
36
byte [ ] publicKey = null ,
36
37
[ CallerMemberName ] string assemblyName = "" ,
37
38
bool allowUnsafe = false )
38
39
{
39
- CSharpCompilation compilation = CreateCSharpCompilationFromSyntax ( syntax , assemblyName , enableNullable , publicKey , allowUnsafe ) ;
40
+ CSharpCompilation compilation = CreateCSharpCompilationFromSyntax ( syntax , assemblyName , enableNullable , publicKey , allowUnsafe , diagnosticOptions ) ;
40
41
41
42
Assert . Empty ( compilation . GetDiagnostics ( ) ) ;
42
43
@@ -76,9 +77,9 @@ public static IAssemblySymbol GetAssemblyFromSyntaxWithReferences(string syntax,
76
77
return compilation . Assembly ;
77
78
}
78
79
79
- private static CSharpCompilation CreateCSharpCompilationFromSyntax ( string syntax , string name , bool enableNullable , byte [ ] publicKey , bool allowUnsafe )
80
+ private static CSharpCompilation CreateCSharpCompilationFromSyntax ( string syntax , string name , bool enableNullable , byte [ ] publicKey , bool allowUnsafe , IEnumerable < KeyValuePair < string , ReportDiagnostic > > diagnosticOptions = null )
80
81
{
81
- CSharpCompilation compilation = CreateCSharpCompilation ( name , enableNullable , publicKey , allowUnsafe ) ;
82
+ CSharpCompilation compilation = CreateCSharpCompilation ( name , enableNullable , publicKey , allowUnsafe , diagnosticOptions ) ;
82
83
return compilation . AddSyntaxTrees ( GetSyntaxTree ( syntax ) ) ;
83
84
}
84
85
@@ -94,15 +95,15 @@ private static SyntaxTree GetSyntaxTree(string syntax)
94
95
return CSharpSyntaxTree . ParseText ( syntax , ParseOptions ) ;
95
96
}
96
97
97
- private static CSharpCompilation CreateCSharpCompilation ( string name , bool enableNullable , byte [ ] publicKey , bool allowUnsafe )
98
+ private static CSharpCompilation CreateCSharpCompilation ( string name , bool enableNullable , byte [ ] publicKey , bool allowUnsafe , IEnumerable < KeyValuePair < string , ReportDiagnostic > > diagnosticOptions = null )
98
99
{
99
100
bool publicSign = publicKey != null ? true : false ;
100
101
var compilationOptions = new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ,
101
102
publicSign : publicSign ,
102
103
cryptoPublicKey : publicSign ? publicKey . ToImmutableArray ( ) : default ,
103
104
nullableContextOptions : enableNullable ? NullableContextOptions . Enable : NullableContextOptions . Disable ,
104
105
allowUnsafe : allowUnsafe ,
105
- specificDiagnosticOptions : DiagnosticOptions ) ;
106
+ specificDiagnosticOptions : diagnosticOptions ?? DiagnosticOptions ) ;
106
107
107
108
return CSharpCompilation . Create ( name , options : compilationOptions , references : DefaultReferences ) ;
108
109
}
0 commit comments