using System; namespace ShrinkModFramework { /// 宿主包装器执行生命周期;Handle 和自动订阅使用 PublicInstance。数据包可返回 null。 public interface IShrinkModWrapper : IShrinkMod { IShrinkMod PublicInstance { get; } } /// /// 延迟模组组件源。Revision 是来源内容的稳定指纹(外部 DLL 可使用文件哈希); /// 同一 ModId 的 revision/metadata 变化由 ShrinkModContextHost 作为替换事务处理。 /// public sealed class ShrinkModComponentSource { public ShrinkModComponentSource(ShrinkModInfo info, string revision, Func factory) { Info = info ?? throw new ArgumentNullException(nameof(info)); if (string.IsNullOrWhiteSpace(info.ModId)) throw new ArgumentException("ModId must not be empty.", nameof(info)); if (string.IsNullOrWhiteSpace(revision)) throw new ArgumentException("Revision must not be empty.", nameof(revision)); Revision = revision.Trim(); Factory = factory ?? throw new ArgumentNullException(nameof(factory)); } public ShrinkModInfo Info { get; } public string Revision { get; } public Func Factory { get; } internal ShrinkExternalModAssemblyLoader.RevisionState DiscoveryState { get; set; } /// 替换清单元数据或生命周期工厂,同时保留授权发现的程序集 revision。 public ShrinkModComponentSource WithMetadata(ShrinkModInfo info, string revision, Func factory = null) => new ShrinkModComponentSource(info, revision, factory ?? Factory) { DiscoveryState = DiscoveryState }; /// 创建无入口类型的数据包;可选生命周期工厂用于注册内容和可逆效应。 public static ShrinkModComponentSource CreateDataOnly(ShrinkModInfo info, string revision, Func factory = null) { if (info == null) throw new ArgumentNullException(nameof(info)); if (info.EntryType != null) throw new ArgumentException("A data-only mod must have no entry type.", nameof(info)); return new ShrinkModComponentSource(info, revision, factory ?? (() => new EmptyDataMod())); } private sealed class EmptyDataMod : ShrinkModBase, IShrinkModWrapper { public IShrinkMod PublicInstance => null; } } }