A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
927 B

using System;
using System.Linq;
using Avalonia.Controls;
namespace UnloadableAssemblyLoadContext;
public class PlugTool
{
public AssemblyLoadContextH? AssemblyLoadContextH;
public WeakReference Unload()
{
var weakReference = new WeakReference(AssemblyLoadContextH);
AssemblyLoadContextH?.Unload();
AssemblyLoadContextH = null;
return weakReference;
}
public Control? FindControl(string type)
{
var type1 = AssemblyLoadContextH!.Assemblies.
FirstOrDefault(x => x.GetName().Name == "UnloadableAssemblyLoadContextPlug")?.
GetType(type);
if (type1 is not null && type1.IsSubclassOf(typeof(Control)))
{
var constructorInfo = type1.GetConstructor([])!.Invoke(null) as Control;
return constructorInfo;
}
return null;
}
}