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); }
/// <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="TMajor">Major Record type of the FormLink</typeparam> /// <typeparam name="TScopedMajor">Major Record type to resolve to</typeparam> public static TScopedMajor?Resolve <TMajor, TScopedMajor>(this IFormLink <TMajor> link, ILinkCache cache) where TMajor : class, IMajorRecordCommonGetter where TScopedMajor : class, TMajor { if (link.TryResolve <TMajor, TScopedMajor>(cache, out var majorRecord)) { return(majorRecord); } return(null); }
/// <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="TMajor">Major Record type to resolve to</typeparam> public static TMajor?Resolve <TMajor>(this IFormLink <TMajor> link, ILinkCache cache) where TMajor : class, IMajorRecordCommonGetter { if (link.FormKeyNullable == null) { return(null); } if (link.TryResolve <TMajor>(cache, out var majorRecord)) { return(majorRecord); } return(null); }
/// <summary> /// Takes in a FormLink, and either returns the existing override definition /// from the Group, or attempts to link and copy the given record, inserting it, and then returning it as an override. /// </summary> /// <param name="group">Group to retrieve and/or insert from</param> /// <param name="link">Link to query and add</param> /// <param name="cache">Cache to query link against</param> /// <param name="rec">Retrieved record if successful</param> /// <returns>True if a record was retrieved</returns> public static bool TryGetOrAddAsOverride <TMajor, TMajorGetter>(this IGroupCommon <TMajor> group, IFormLink <TMajorGetter> link, ILinkCache cache, [MaybeNullWhen(false)] out TMajor rec) where TMajor : class, IMajorRecordInternal, TMajorGetter where TMajorGetter : class, IMajorRecordGetter, IBinaryItem { try { if (group.RecordCache.TryGetValue(link.FormKey, out rec)) { return(true); } if (!link.TryResolve <TMajorGetter>(cache, out var getter)) { rec = default; return(false); } rec = GetOrAddAsOverride(group, getter); return(true); } catch (Exception ex) { throw RecordException.Factory(ex, link.FormKey, edid: null); } }