Fetch the repository succeeded.
using Fireasy.Common.Compiler;
using Fireasy.Tests.Base;
using Microsoft.Extensions.DependencyInjection;
namespace Fireasy.Common.Tests
{
[TestClass]
public class CodeCompilerTests : ServiceProviderBaseTests
{
[TestMethod]
public void TestCompileAssembly()
{
var source = @"
public class A
{
public string Hello(string str)
{
return str;
}
}";
var codeCompilerManager = ServiceProvider.GetService<ICodeCompilerManager>();
var codeCompiler = codeCompilerManager!.CreateCompiler("csharp");
var opt = new ConfigureOptions();
opt.Assemblies.Add("System.Core.dll");
var assembly = codeCompiler!.CompileAssembly(source, opt);
var type = assembly!.GetType("A");
Assert.IsNotNull(type);
}
/// <summary>
/// 使用vb源代码
/// </summary>
[TestMethod]
public void TestCompileAssemblyUseVb()
{
var source = @"
Public Class A
Public Function Hello(ByVal str As String) As String
Return str
End Function
End Class";
var codeCompilerManager = ServiceProvider.GetService<ICodeCompilerManager>();
var codeCompiler = codeCompilerManager!.CreateCompiler("vb");
var assembly = codeCompiler!.CompileAssembly(source);
var type = assembly!.GetType("A");
Assert.IsNotNull(type);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。