Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Compilation CreateTestCompilation()
- => CSharpCompilation.Create(
- assemblyName: "ConsoleApplication",
- syntaxTrees: new[] {
- SyntaxTreeFromPath(@"Program.cs"),
- SyntaxTreeFromPath(@"InitializerRewriter.cs")
- },
- references: new[] {
- MetadataReferenceFromType<object>(), // mscorlib
- MetadataReferenceFromType<SyntaxTree>(), // CodeAnalysis
- MetadataReferenceFromType<CSharpSyntaxTree>() // CSharpCodeAnalysis
- },
- options: new CSharpCompilationOptions(OutputKind.ConsoleApplication)
- );
- private static SyntaxTree SyntaxTreeFromPath(string path)
- => CSharpSyntaxTree.ParseText(File.ReadAllText(path)).WithFilePath(path);
- private static MetadataReference MetadataReferenceFromType<T>()
- => MetadataReference.CreateFromFile(typeof(T).GetTypeInfo().Assembly.Location);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement