private void GenerateForQueue(ContainerDefinition containerDefinition) { Type type = containerDefinition.Type; if (!this.CheckIfPrimitiveOrPrimiteHolderStruct(type.GetGenericArguments()[0])) { return; } MethodCode methodCode = new MethodCode(); methodCode.IsStatic = true; methodCode.AccessModifier = MethodCodeAccessModifier.Private; methodCode.Name = "AutoGeneratedStaticCollectObjectsForQueue" + (object)this._containerNumber; methodCode.MethodSignature = "(object o, global::System.Collections.Generic.List<object> collectedObjects)"; methodCode.AddLine("//Got no child, type: " + type.FullName); SaveId saveId = containerDefinition.SaveId; StringWriter stringWriter1 = new StringWriter(); StringWriter stringWriter2 = stringWriter1; saveId.WriteTo((IWriter)stringWriter2); this._managerMethod.AddLine("var saveId" + (object)this._delegateCount + " = global::TaleWorlds.SaveSystem.Definition.SaveId.ReadSaveIdFrom(new global::TaleWorlds.Library.StringReader(\"" + stringWriter1.Data + "\"));"); this._managerMethod.AddLine("var typeDefinition" + (object)this._delegateCount + " = (global::TaleWorlds.SaveSystem.Definition.ContainerDefinition)definitionContext.TryGetTypeDefinition(saveId" + (object)this._delegateCount + ");"); this._managerMethod.AddLine("TaleWorlds.SaveSystem.Definition.CollectObjectsDelegate d" + (object)this._delegateCount + " = " + methodCode.Name + ";"); this._managerMethod.AddLine("typeDefinition" + (object)this._delegateCount + ".InitializeForAutoGeneration(d" + (object)this._delegateCount + ", true);"); this._managerMethod.AddLine(""); ++this._delegateCount; this._managerClass.AddMethod(methodCode); ++this._containerNumber; }
private void GenerateForArray(ContainerDefinition containerDefinition) { Type type = containerDefinition.Type; Type elementType = type.GetElementType(); bool flag = this.CheckIfPrimitiveOrPrimiteHolderStruct(elementType); TypeDefinition structDefinition = this._definitionContext.GetStructDefinition(elementType); if (!(elementType != typeof(object))) { return; } MethodCode methodCode = new MethodCode(); methodCode.IsStatic = true; methodCode.AccessModifier = MethodCodeAccessModifier.Private; methodCode.Name = "AutoGeneratedStaticCollectObjectsForArray" + (object)this._containerNumber; methodCode.MethodSignature = "(object o, global::System.Collections.Generic.List<object> collectedObjects)"; if (flag) { methodCode.AddLine("//Got no child, type: " + type.FullName); } else if (structDefinition != null) { string str1 = elementType.FullName.Replace('+', '.'); string str2 = type.FullName.Replace('+', '.'); methodCode.AddLine("var target = (global::" + str2 + ")o;"); methodCode.AddLine(""); methodCode.AddLine("for (int i = 0; i < target.Length; i++)"); methodCode.AddLine("{"); methodCode.AddLine("var element = target[i];"); methodCode.AddLine(""); methodCode.AddLine("global::" + str1 + ".AutoGeneratedStaticCollectObjects" + elementType.Name + "(element, collectedObjects);"); methodCode.AddLine("}"); } else { methodCode.AddLine("var target = (global::System.Array)o;"); methodCode.AddLine(""); methodCode.AddLine("for (int i = 0; i < target.Length; i++)"); methodCode.AddLine("{"); methodCode.AddLine("var element = target.GetValue(i);"); methodCode.AddLine("collectedObjects.Add(element);"); methodCode.AddLine("}"); } SaveId saveId = containerDefinition.SaveId; StringWriter stringWriter1 = new StringWriter(); StringWriter stringWriter2 = stringWriter1; saveId.WriteTo((IWriter)stringWriter2); string str = flag ? "true" : "false"; this._managerMethod.AddLine("var saveId" + (object)this._delegateCount + " = global::TaleWorlds.SaveSystem.Definition.SaveId.ReadSaveIdFrom(new global::TaleWorlds.Library.StringReader(\"" + stringWriter1.Data + "\"));"); this._managerMethod.AddLine("var typeDefinition" + (object)this._delegateCount + " = (global::TaleWorlds.SaveSystem.Definition.ContainerDefinition)definitionContext.TryGetTypeDefinition(saveId" + (object)this._delegateCount + ");"); this._managerMethod.AddLine("TaleWorlds.SaveSystem.Definition.CollectObjectsDelegate d" + (object)this._delegateCount + " = " + methodCode.Name + ";"); this._managerMethod.AddLine("typeDefinition" + (object)this._delegateCount + ".InitializeForAutoGeneration(d" + (object)this._delegateCount + ", " + str + ");"); this._managerMethod.AddLine(""); ++this._delegateCount; this._managerClass.AddMethod(methodCode); ++this._containerNumber; }
private void GenerateForDictionary(ContainerDefinition containerDefinition) { Type type = containerDefinition.Type; Type genericArgument1 = type.GetGenericArguments()[0]; Type genericArgument2 = type.GetGenericArguments()[1]; int num = this.CheckIfPrimitiveOrPrimiteHolderStruct(genericArgument1) ? 1 : 0; bool flag1 = this.CheckIfPrimitiveOrPrimiteHolderStruct(genericArgument2); TypeDefinition structDefinition1 = this._definitionContext.GetStructDefinition(genericArgument1); TypeDefinition structDefinition2 = this._definitionContext.GetStructDefinition(genericArgument2); bool flag2 = (num & (flag1 ? 1 : 0)) != 0; if (num == 0 && structDefinition1 == null || !flag1 && structDefinition2 == null || (!(genericArgument1 != typeof(object)) || !(genericArgument2 != typeof(object)))) { return; } MethodCode methodCode = new MethodCode(); methodCode.IsStatic = true; methodCode.AccessModifier = MethodCodeAccessModifier.Private; methodCode.Name = "AutoGeneratedStaticCollectObjectsForDictionary" + (object)this._containerNumber; methodCode.MethodSignature = "(object o, global::System.Collections.Generic.List<object> collectedObjects)"; if (flag2) { methodCode.AddLine("//Got no child, type: " + type.FullName); } else { methodCode.AddLine("var target = (global::System.Collections.IDictionary)o;"); methodCode.AddLine(""); if (structDefinition1 != null) { string str = genericArgument1.FullName.Replace('+', '.'); methodCode.AddLine("foreach (var key in target.Keys)"); methodCode.AddLine("{"); methodCode.AddLine("global::" + str + ".AutoGeneratedStaticCollectObjects" + genericArgument1.Name + "(key, collectedObjects);"); methodCode.AddLine("}"); } methodCode.AddLine(""); if (structDefinition2 != null) { string str = genericArgument2.FullName.Replace('+', '.'); methodCode.AddLine("foreach (var value in target.Values)"); methodCode.AddLine("{"); methodCode.AddLine("global::" + str + ".AutoGeneratedStaticCollectObjects" + genericArgument2.Name + "(value, collectedObjects);"); methodCode.AddLine("}"); } } SaveId saveId = containerDefinition.SaveId; StringWriter stringWriter1 = new StringWriter(); StringWriter stringWriter2 = stringWriter1; saveId.WriteTo((IWriter)stringWriter2); string str1 = flag2 ? "true" : "false"; this._managerMethod.AddLine("var saveId" + (object)this._delegateCount + " = global::TaleWorlds.SaveSystem.Definition.SaveId.ReadSaveIdFrom(new global::TaleWorlds.Library.StringReader(\"" + stringWriter1.Data + "\"));"); this._managerMethod.AddLine("var typeDefinition" + (object)this._delegateCount + " = (global::TaleWorlds.SaveSystem.Definition.ContainerDefinition)definitionContext.TryGetTypeDefinition(saveId" + (object)this._delegateCount + ");"); this._managerMethod.AddLine("TaleWorlds.SaveSystem.Definition.CollectObjectsDelegate d" + (object)this._delegateCount + " = " + methodCode.Name + ";"); this._managerMethod.AddLine("typeDefinition" + (object)this._delegateCount + ".InitializeForAutoGeneration(d" + (object)this._delegateCount + ", " + str1 + ");"); this._managerMethod.AddLine(""); ++this._delegateCount; this._managerClass.AddMethod(methodCode); ++this._containerNumber; }