VBCodeProvider.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP
  2. using Microsoft.CodeAnalysis;
  3. using Microsoft.CodeAnalysis.Emit;
  4. using Microsoft.CodeAnalysis.VisualBasic;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Reflection;
  9. using System.Text;
  10. using FastReport.Code.CodeDom.Compiler;
  11. using System.Threading;
  12. namespace FastReport.Code.VisualBasic
  13. {
  14. public class VBCodeProvider : CodeDomProvider
  15. {
  16. public override void Dispose()
  17. {
  18. }
  19. protected override Compilation CreateCompilation(SyntaxTree codeTree, ICollection<MetadataReference> references)
  20. {
  21. VisualBasicCompilationOptions options = new VisualBasicCompilationOptions(
  22. OutputKind.DynamicallyLinkedLibrary,
  23. true,
  24. embedVbCoreRuntime: true,
  25. optimizationLevel: OptimizationLevel.Release,
  26. generalDiagnosticOption: ReportDiagnostic.Default);
  27. Compilation compilation = VisualBasicCompilation.Create(
  28. "_" + Guid.NewGuid().ToString("D"), new SyntaxTree[] { codeTree },
  29. references: references, options: options
  30. );
  31. return compilation;
  32. }
  33. protected override SyntaxTree ParseTree(string text, CancellationToken ct = default)
  34. => VisualBasicSyntaxTree.ParseText(text,
  35. cancellationToken: ct);
  36. }
  37. }
  38. #endif