VBCodeProvider.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. var options = new Microsoft.CodeAnalysis.VisualBasic.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. public class VisualBasicCompilationOptions
  38. {
  39. public VisualBasicCompilationOptions(OutputKind dynamicallyLinkedLibrary, bool b, bool embedVbCoreRuntime, OptimizationLevel optimizationLevel, ReportDiagnostic generalDiagnosticOption)
  40. {
  41. throw new NotImplementedException();
  42. }
  43. }
  44. }
  45. #endif