private async Task LoquiTypeHandler( FileGeneration fg, ObjectGeneration obj, Accessor loquiAccessor, LoquiType loquiType, Action <ArgsWrapper> addGetOrAddArg, string generic, bool checkType, bool includeSelf = true) { // ToDo // Quick hack. Real solution should use reflection to investigate the interface if (loquiType.RefType == LoquiType.LoquiRefType.Interface) { if (checkType) { fg.AppendLine($"if (type.IsAssignableFrom({loquiAccessor}.GetType()))"); } using (new BraceWrapper(fg, doIt: checkType)) { using (var args = new ArgsWrapper(fg, $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>")) { args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}"); args.Add($"record: {loquiAccessor}"); args.Add($"parent: curContext"); addGetOrAddArg(args); } } return; } if (includeSelf && loquiType.TargetObjectGeneration != null && await loquiType.TargetObjectGeneration.IsMajorRecord()) { if (checkType) { fg.AppendLine($"if (type.IsAssignableFrom({loquiAccessor}.GetType()))"); } using (new BraceWrapper(fg, doIt: checkType)) { using (var args = new ArgsWrapper(fg, $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>")) { args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}"); args.Add($"record: {loquiAccessor}"); args.Add($"parent: curContext"); addGetOrAddArg(args); } } } if (await MajorRecordModule.HasMajorRecords(loquiType, includeBaseClass: true, includeSelf: false) == Case.No) { return; } if (obj.IsListGroup()) { return; } if (obj.IsTopLevelGroup()) { fg.AppendLine($"foreach (var item in {loquiAccessor}.EnumerateMajorRecords({(generic == null ? null : "type, throwIfUnknown: false")}))"); using (new BraceWrapper(fg)) { using (var args = new ArgsWrapper(fg, $"yield return new ModContext<{obj.GetObjectData().GameCategory.Value.ModInterface(getter: false)}, IMajorRecordCommon, IMajorRecordCommonGetter>")) { args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}"); args.Add("record: item"); args.Add($"getOrAddAsOverride: (m, r) => m.{loquiType.Name}.GetOrAddAsOverride(({loquiType.GetGroupTarget().Interface(getter: true, internalInterface: true)})r)"); } } } else { using (var args = new ArgsWrapper(fg, $"foreach (var item in {loquiType.TargetObjectGeneration.CommonClassInstance(loquiAccessor, LoquiInterfaceType.IGetter, CommonGenerics.Class)}.EnumerateMajorRecordContexts", suffixLine: ")") { SemiColon = false }) { args.Add($"obj: {loquiAccessor}"); args.AddPassArg("linkCache"); args.AddPassArg("type"); args.Add($"modKey: {(obj.GetObjectType() == ObjectType.Mod ? "obj.ModKey" : "modKey")}"); args.Add($"parent: {(obj.GetObjectType() == ObjectType.Mod ? "null" : "curContext")}"); args.Add("throwIfUnknown: false"); addGetOrAddArg(args); } using (new BraceWrapper(fg)) { fg.AppendLine("yield return item;"); } } }