热使用动态链接库dynamic loading
$ dotnet add package rehot热hot 是一个实现快速 热加载、热更新、热重载、动态调用等一系列操作 .dll 动态链接库的库。
您可以用它来加快、简化需要高频更改或 不稳定的项目最新内容的推送。
var dll = new HotDLL("excelconfig.dll");
var globalsetting = dll.FindType("GlobalSetting");
var a = globalsetting.Read<string>("NO");
Console.WriteLine(a);
var type_appconfigfile = dll.FindType("AppConfigFile");
var testconfig = type_appconfigfile.New(HotParam.Put("."), HotParam.Put("test"));
var b = testconfig.Call<string>("Text", HotParam.Put("test"));
Console.WriteLine(b);
HotOneDLL 不占用文件,需要您在使用前进行更新操作。
var dll = new HotOneDLL("excelconfig.dll");
! 内存载入不会主动加载依赖,适合依赖已全部导入后的项目。
HotDLL 会占用文件,需要您在首次载入前进行更新操作。
var dll = new HotDLL("excelconfig.dll");
! 这虽然会主动载入依赖,但面对某些复杂依赖的情况,你需要提前将这些依赖引用到主项目中并编译。
HotVirtual 虚拟载入时,会与当前域隔离,且释放后不占用文件。
using (var domain = new HotVirtual())
{
domain.LoadDLL("./SanlieHash.dll");
domain.LoadDLL("./yacomp.dll");
domain.LoadDLL("./ExcelConfig3.dll");
domain.GetContainer().Run(container =>
{
var dll_ec = container.UseDLL("ExcelConfig");
var f = dll_ec.FindType("AppConfigFile");
using (var test_config = f.New(HotParam.Put("./test.config.xlsx")))
{
var test = test_config.Call<string>("Text", HotParam.Put("test"));
Console.WriteLine(test);
}
});
}
! 如遇到释放后dll文件仍占用的情况,请检查是否即时释放该dll中的资源。
当IDisposable被调用时,自动寻找Dispose方法并调用。
var _enum = HotEnum.LoadByType<TestEnum>();
Console.WriteLine(_enum.New(HotParam.Put(3)).Name);
foreach (var item in _enum.AllMembers()) Console.WriteLine($"{item.Key}: {item.Value}");
public void AddEvent(string name, params IHotEvent[] events)
public void RemoveEvent(string name, params IHotEvent[] events)
// 获取dll内部的嵌入资源示例
var dll = new HotOneDLL("excelconfig.dll");
using (var s = dll.FindResource("app.config.xlsx"))
using (var f = File.Create("test2.xlsx"))
{
s.CopyTo(f);
f.Flush();
}
Console.WriteLine(dll.FindAttribute("TargetFramework").Read<string>("FrameworkName"));
foreach (var id in dll_ec.FindTypesIdByInterface("IExcelConfig"))
{
Console.WriteLine(id);
var t = dll_ec.FindTypeById(id);
Console.WriteLine(t.Name);
}