public override void GenerateForCopy( StructuredStringBuilder sb, Accessor accessor, Accessor rhs, Accessor copyMaskAccessor, bool protectedMembers, bool deepCopy) { void GenerateSet() { if (isLoquiSingle) { if (deepCopy) { LoquiType loqui = SubTypeGeneration as LoquiType; WrapSet(sb, accessor, (f) => { f.AppendLine(rhs.ToString()); f.AppendLine(".Select(r =>"); using (new CurlyBrace(f) { AppendParenthesis = true }) { loqui.GenerateTypicalMakeCopy( f, retAccessor: $"return ", rhsAccessor: Accessor.FromType(loqui, "r"), copyMaskAccessor: copyMaskAccessor, deepCopy: deepCopy, doTranslationMask: false); } }); } else { LoquiType loqui = SubTypeGeneration as LoquiType; using (var args = sb.Call( $"{accessor}.SetTo<{SubTypeGeneration.TypeName(getter: false)}, {SubTypeGeneration.TypeName(getter: false)}>")) { args.Add($"items: {rhs}"); args.Add((gen) => { gen.AppendLine("converter: (r) =>"); using (new CurlyBrace(gen)) { var supportsCopy = loqui.SupportsMask(MaskType.Copy); var accessorStr = $"copyMask?.{Name}{(supportsCopy ? ".Overall" : string.Empty)}"; gen.AppendLine($"switch ({accessorStr} ?? {nameof(CopyOption)}.{nameof(CopyOption.Reference)})"); using (new CurlyBrace(gen)) { gen.AppendLine($"case {nameof(CopyOption)}.{nameof(CopyOption.Reference)}:"); using (gen.IncreaseDepth()) { gen.AppendLine($"return ({loqui.TypeName()})r;"); } gen.AppendLine($"case {nameof(CopyOption)}.{nameof(CopyOption.MakeCopy)}:"); using (gen.IncreaseDepth()) { loqui.GenerateTypicalMakeCopy( gen, retAccessor: $"return ", rhsAccessor: new Accessor("r"), copyMaskAccessor: copyMaskAccessor, deepCopy: deepCopy, doTranslationMask: false); } gen.AppendLine($"default:"); using (gen.IncreaseDepth()) { gen.AppendLine($"throw new NotImplementedException($\"Unknown {nameof(CopyOption)} {{{accessorStr}}}. Cannot execute copy.\");"); } } } }); } } } else { WrapSet(sb, accessor, (f) => { f.AppendLine($"rhs.{Name}"); SubTypeGeneration.GenerateCopySetToConverter(f); }); } } if (!AlwaysCopy) { sb.AppendLine($"if ({(deepCopy ? GetTranslationIfAccessor(copyMaskAccessor) : SkipCheck(copyMaskAccessor, deepCopy))})"); } using (sb.CurlyBrace(doIt: !AlwaysCopy)) { MaskGenerationUtility.WrapErrorFieldIndexPush( sb, () => { if (Nullable) { sb.AppendLine($"if ({NullableAccessor(getter: false, rhs)})"); using (sb.CurlyBrace()) { GenerateSet(); } sb.AppendLine("else"); using (sb.CurlyBrace()) { GenerateClear(sb, accessor); } } else { GenerateSet(); } }, errorMaskAccessor: "errorMask", indexAccessor: HasIndex?IndexEnumInt: default(Accessor), doIt: CopyNeedsTryCatch); } }
public string TypeTuple(bool getter) => $"{KeyTypeGen.TypeName(getter)}, {ValueTypeGen.TypeName(getter)}";