internal ContainerDefinition ConstructContainerDefinition( Type type, Assembly definedAssembly) { ContainerType containerType; type.IsContainer(out containerType); SaveId keyId = (SaveId)null; SaveId valueId = (SaveId)null; switch (containerType) { case ContainerType.List: keyId = this.GetTypeDefinition(type.GenericTypeArguments[0]).SaveId; break; case ContainerType.Dictionary: keyId = this.GetTypeDefinition(type.GenericTypeArguments[0]).SaveId; valueId = this.GetTypeDefinition(type.GenericTypeArguments[1]).SaveId; break; case ContainerType.Array: keyId = this.GetTypeDefinition(type.GetElementType()).SaveId; break; case ContainerType.Queue: keyId = this.GetTypeDefinition(type.GenericTypeArguments[0]).SaveId; break; } ContainerSaveId saveId = new ContainerSaveId(containerType, keyId, valueId); ContainerDefinition containerDefinition = new ContainerDefinition(type, saveId, definedAssembly); this.AddContainerDefinition(containerDefinition); return(containerDefinition); }
public static ContainerSaveId ReadFrom(IReader reader) { ContainerType containerType = (ContainerType)reader.ReadByte(); int num = containerType == ContainerType.Dictionary ? 2 : 1; List <SaveId> saveIdList = new List <SaveId>(); for (int index = 0; index < num; ++index) { SaveId saveId = (SaveId)null; switch (reader.ReadByte()) { case 0: saveId = (SaveId)TypeSaveId.ReadFrom(reader); break; case 1: saveId = (SaveId)GenericSaveId.ReadFrom(reader); break; case 2: saveId = (SaveId)ContainerSaveId.ReadFrom(reader); break; } saveIdList.Add(saveId); } SaveId keyId = saveIdList[0]; SaveId valueId = saveIdList.Count > 1 ? saveIdList[1] : (SaveId)null; return(new ContainerSaveId(containerType, keyId, valueId)); }
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; }
public ContainerSaveId(ContainerType containerType, SaveId keyId, SaveId valueId) { this.ContainerType = containerType; this.KeyId = keyId; this.ValueId = valueId; this._stringId = this.CalculateStringId(); }
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; }
public static GenericSaveId ReadFrom(IReader reader) { int num1 = (int)reader.ReadByte(); TypeSaveId baseId = TypeSaveId.ReadFrom(reader); byte num2 = reader.ReadByte(); List <SaveId> saveIdList = new List <SaveId>(); for (int index = 0; index < (int)num2; ++index) { SaveId saveId = (SaveId)null; switch (reader.ReadByte()) { case 0: saveId = (SaveId)TypeSaveId.ReadFrom(reader); break; case 1: saveId = (SaveId)GenericSaveId.ReadFrom(reader); break; case 2: saveId = (SaveId)ContainerSaveId.ReadFrom(reader); break; } saveIdList.Add(saveId); } return(new GenericSaveId(baseId, saveIdList.ToArray())); }
public TypeDefinition(Type type, SaveId saveId, IObjectResolver objectResolver) : base(type, saveId) { this._isClass = this.Type.IsClass; this._errors = new List <string>(); this._properties = new Dictionary <MemberTypeId, PropertyDefinition>(); this._fields = new Dictionary <MemberTypeId, FieldDefinition>(); this.MemberDefinitions = new List <MemberDefinition>(); this.CustomFields = new List <CustomField>(); this._initializationCallbacks = new List <MethodInfo>(); this.ObjectResolver = objectResolver; }
private string CalculateStringId() { string str = ""; for (int index = 0; index < this.GenericTypeIDs.Length; ++index) { if (index != 0) { str += ","; } SaveId genericTypeId = this.GenericTypeIDs[index]; str += genericTypeId.GetStringId(); } return("G(" + this.BaseId.GetStringId() + ")-(" + str + ")"); }
public TypeDefinitionBase TryGetTypeDefinition(SaveId saveId) { TypeDefinitionBase typeDefinitionBase; if (this._allTypeDefinitionsWithId.TryGetValue(saveId, out typeDefinitionBase)) { return(typeDefinitionBase); } if (saveId is GenericSaveId) { GenericSaveId saveId1 = (GenericSaveId)saveId; if (this.TryGetTypeDefinition(saveId1.BaseId) is TypeDefinition typeDefinition3) { TypeDefinitionBase[] parameterDefinitions = new TypeDefinitionBase[saveId1.GenericTypeIDs.Length]; for (int index = 0; index < saveId1.GenericTypeIDs.Length; ++index) { TypeDefinitionBase typeDefinition = this.TryGetTypeDefinition(saveId1.GenericTypeIDs[index]); if (typeDefinition == null) { return((TypeDefinitionBase)null); } parameterDefinitions[index] = typeDefinition; } Type type = this.ConstructTypeFrom(typeDefinition3, parameterDefinitions); if (type != (Type)null) { GenericTypeDefinition genericTypeDefinition = new GenericTypeDefinition(type, saveId1); genericTypeDefinition.CollectInitializationCallbacks(); genericTypeDefinition.CollectFields(); genericTypeDefinition.CollectProperties(); if (genericTypeDefinition.IsClassDefinition) { this.AddGenericClassDefinition(genericTypeDefinition); } else { this.AddGenericStructDefinition(genericTypeDefinition); } return((TypeDefinitionBase)genericTypeDefinition); } } } return((TypeDefinitionBase)null); }
public static SaveId ReadSaveIdFrom(IReader reader) { byte num = reader.ReadByte(); SaveId saveId = (SaveId)null; switch (num) { case 0: saveId = (SaveId)TypeSaveId.ReadFrom(reader); break; case 1: saveId = (SaveId)GenericSaveId.ReadFrom(reader); break; case 2: saveId = (SaveId)ContainerSaveId.ReadFrom(reader); break; } return(saveId); }
internal GenericTypeDefinition ConstructGenericStructDefinition(Type type) { TypeDefinition structDefinition = this.GetStructDefinition(type.GetGenericTypeDefinition()); TypeSaveId saveId1 = (TypeSaveId)structDefinition.SaveId; SaveId[] saveIds = new SaveId[type.GenericTypeArguments.Length]; for (int index = 0; index < type.GenericTypeArguments.Length; ++index) { TypeDefinitionBase typeDefinition = this.GetTypeDefinition(type.GenericTypeArguments[index]); saveIds[index] = typeDefinition.SaveId; } GenericSaveId saveId2 = new GenericSaveId(saveId1, saveIds); GenericTypeDefinition genericStructDefinition = new GenericTypeDefinition(type, saveId2); foreach (CustomField customField in structDefinition.CustomFields) { genericStructDefinition.AddCustomField(customField.Name, customField.SaveId); } genericStructDefinition.CollectFields(); genericStructDefinition.CollectProperties(); this.AddGenericStructDefinition(genericStructDefinition); return(genericStructDefinition); }
protected TypeDefinitionBase(Type type, SaveId saveId) { this.Type = type; this.SaveId = saveId; this.TypeLevel = TypeDefinitionBase.GetClassLevel(type); }
public ContainerSaveId(ContainerType containerType, SaveId elementId) { this.ContainerType = containerType; this.KeyId = elementId; this._stringId = this.CalculateStringId(); }
public EnumDefinition(Type type, SaveId saveId) : base(type, saveId) { }
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; }
public InterfaceDefinition(Type type, SaveId saveId) : base(type, saveId) { }