示例#1
0
        public static void FormLink()
        {
            var mod   = new SkyrimMod(Utility.LightMasterModKey, SkyrimRelease.SkyrimLE);
            var light = mod.Lights.AddNew();
            var cache = mod.ToImmutableLinkCache();

            var link         = new FormLink <ISkyrimMajorRecordGetter>(light.FormKey);
            var nullableLink = new FormLinkNullable <ISkyrimMajorRecordGetter>(light.FormKey);
            IFormLink <ISkyrimMajorRecordGetter> iLink = link;

            // Normal resolution
            link.TryResolve(cache, out var _);
            link.TryResolve(cache, out ISkyrimMajorRecordGetter _);
            link.Resolve(cache);
            link.TryResolve <ILightGetter>(cache, out var _);
            link.TryResolve(cache, out ILightGetter _);
            link.Resolve <ILightGetter>(cache);

            nullableLink.TryResolve(cache, out var _);
            nullableLink.TryResolve(cache, out ISkyrimMajorRecordGetter _);
            nullableLink.Resolve(cache);
            nullableLink.TryResolve <ILightGetter>(cache, out var _);
            nullableLink.TryResolve(cache, out ILightGetter _);
            nullableLink.Resolve <ILightGetter>(cache);

            iLink.TryResolve(cache, out var _);
            iLink.Resolve(cache);
            iLink.TryResolve <ISkyrimMajorRecordGetter, ILightGetter>(cache, out var _);
            iLink.TryResolve(cache, out ILightGetter _);
            iLink.Resolve <ISkyrimMajorRecordGetter, ILightGetter>(cache);

            // Context resolution
            // ToDo
            // Enable when generic querying is supported
            //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _);
            //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _);
            //link.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache);
            link.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _);
            link.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _);
            link.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache);

            //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _);
            //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _);
            //nullableLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache);
            nullableLink.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _);
            nullableLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _);
            nullableLink.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache);

            //iLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _);
            //iLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache);
            iLink.TryResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _);
            iLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _);
            iLink.ResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache);
        }
示例#2
0
 /// <summary>
 /// Locates link winning target record in given Link Cache.
 /// </summary>
 /// <param name="link">Link to resolve</param>
 /// <param name="cache">Link Cache to resolve against</param>
 /// <returns>Located Major Record</returns>
 /// <exception cref="NullReferenceException">If link was not succesful</exception>
 /// <typeparam name="TMod">Mod setter type that can be overridden into</typeparam>
 /// <typeparam name="TMajorSetter">Major Record setter type to resolve to</typeparam>
 /// <typeparam name="TMajorGetter">Major Record getter type to resolve to</typeparam>
 public static IModContext <TMod, TMajorSetter, TMajorGetter>?ResolveContext <TMod, TMajorSetter, TMajorGetter>(
     this IFormLink <TMajorGetter> link,
     ILinkCache <TMod> cache)
     where TMod : class, IContextMod <TMod>
     where TMajorSetter : class, IMajorRecordCommon, TMajorGetter
     where TMajorGetter : class, IMajorRecordCommonGetter
 {
     if (link.TryResolveContext <TMod, TMajorSetter, TMajorGetter>(cache, out var majorRecord))
     {
         return(majorRecord);
     }
     return(null);
 }