3 Star 13 Fork 5

faib920/fireasy3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DefaultCodeCompilerManager.cs 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
faib920 提交于 2年前 . emit 和代码编译器
// -----------------------------------------------------------------------
// <copyright company="Fireasy"
// email="faib920@126.com"
// qq="55570729">
// (c) Copyright Fireasy. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using Fireasy.Common.Extensions;
using Fireasy.Common.ObjectActivator;
using Microsoft.Extensions.DependencyInjection;
namespace Fireasy.Common.Compiler
{
/// <summary>
/// 缺省的代码编译器管理器。
/// </summary>
public class DefaultCodeCompilerManager : ICodeCompilerManager
{
private readonly Dictionary<string, Type> _languageMappers = new(new StringIgnoreCaseComparer());
private class StringIgnoreCaseComparer : IEqualityComparer<string>
{
public bool Equals(string x, string y)
{
return string.Compare(x, y, true) == 0;
}
public int GetHashCode(string obj)
{
return obj?.GetHashCode() ?? 0;
}
}
/// <summary>
/// 初始化 <see cref="DefaultCodeCompilerManager"/> 类新实例。
/// </summary>
public DefaultCodeCompilerManager()
{
Register<CSharpCodeCompiler>("csharp", "c#");
}
/// <summary>
/// 注册指定语言类型的代码编译器类型。
/// </summary>
/// <typeparam name="TCompiler"></typeparam>
/// <param name="languages">语言。</param>
public void Register<TCompiler>(params string[] languages) where TCompiler : ICodeCompiler
{
foreach (var language in languages)
{
_languageMappers.AddOrReplace(language, typeof(TCompiler));
}
}
/// <summary>
/// 创建代码编译器。
/// </summary>
/// <param name="language">语言。</param>
/// <returns></returns>
public ICodeCompiler? CreateCompiler(string language)
{
if (_languageMappers.TryGetValue(language, out var compilerType))
{
return Activator.CreateInstance(compilerType) as ICodeCompiler;
}
return null;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/faib920/fireasy3.git
git@gitee.com:faib920/fireasy3.git
faib920
fireasy3
fireasy3
dev3.0

搜索帮助