public ComplexData Clone() { var clone = (ComplexData)MemberwiseClone(); clone.ListOfInts = ListOfInts?.ToList(); clone.nestedSimple = nestedSimple?.Clone(); return(clone); }
public SimpleData SomeClassB; // Classes are automatically implemented in the UI. // See ??? for an example of a class with a CustomUI. // Proper cloning of reference types is required because behind the scenes many instances of ModConfig classes co-exist. public override ModConfig Clone() { // Since ListOfInts is a reference type, we need to clone it manually so our config works properly. var clone = (ModConfigShowcaseDataTypes)base.Clone(); // We use ?. and ?: here because many of these fields can be null. // clone.SomeList = SomeList != null ? new List<int>(SomeList) : null; clone.SomeArray = (int[])SomeArray.Clone(); clone.SomeList = SomeList?.ToList(); clone.SomeDictionary = SomeDictionary?.ToDictionary(i => i.Key, i => i.Value); clone.SomeSet = SomeSet != null ? new HashSet <string>(SomeSet) : null; clone.SomeClassA = SomeClassA == null ? null : new ItemDefinition(SomeClassA.mod, SomeClassA.name); clone.SomeClassB = SomeClassB?.Clone(); return(clone); }
public override ModConfig Clone() { // Since ListOfInts is a reference type, we need to clone it manually so our config works properly. var clone = (ModConfigShowcaseMisc)base.Clone(); // We use ?. and ?: here because many of these fields can be null. // clone.ListOfInts = ListOfInts != null ? new List<int>(ListOfInts) : null; clone.gradient = gradient == null ? null : gradient.Clone(); clone.StringPairDictionary = StringPairDictionary.ToDictionary(i => i.Key, i => i.Value?.Clone()); clone.JsonItemFloatDictionary = JsonItemFloatDictionary.ToDictionary(i => new ItemDefinition(i.Key.mod, i.Key.name), i => i.Value); clone.itemSet = new HashSet <ItemDefinition>(itemSet); clone.ListOfPair2 = ListOfPair2?.ConvertAll(pair => pair.Clone()); clone.pairExample2 = pairExample2 == null ? null : pairExample2.Clone(); clone.simpleDataExample = simpleDataExample == null ? null : simpleDataExample.Clone(); clone.simpleDataExample2 = simpleDataExample2 == null ? null : simpleDataExample2.Clone(); clone.complexData = complexData == null ? null : complexData.Clone(); return(clone); }