/// <summary> /// 使用一个域来初始化编译单元 /// </summary> /// <inheritdoc cref="CreateDomain" path="//*[not(self::summary)]"/> public static T UseDomain(NatashaReferenceDomain domain, Action <AssemblyCSharpBuilder>?option = default) { T instance = new(); instance.AssemblyBuilder.Domain = domain; instance.OptionAction = option; option?.Invoke(instance.AssemblyBuilder); return(instance); }
public static void Add(string key, NatashaReferenceDomain domain) { if (Cache.ContainsKey(key)) { if (!Cache[key].IsAlive) { Cache[key] = new WeakReference(domain); } } else { Cache[key] = new WeakReference(domain, trackResurrection: true); } }
public static NatashaReferenceDomain Create(string key) { if (Cache.ContainsKey(key)) { return((NatashaReferenceDomain)(Cache[key].Target !)); } else { Clear(); var domain = new NatashaReferenceDomain(key); Add(key, domain); return(domain); } }
static NatashaReferenceDomain() { DefaultDomain = new NatashaReferenceDomain(); DomainManagement.Add("Default", DefaultDomain); }