3 Star 13 Fork 4

faib920/fireasy3

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
CodeCompilerTests.cs 1.45 KB
Copy Edit Raw Blame History
faib920 authored 2023-03-29 23:45 . 完善
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);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/faib920/fireasy3.git
git@gitee.com:faib920/fireasy3.git
faib920
fireasy3
fireasy3
dev3.0

Search