Beispiel #1
0
        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));
        }
Beispiel #2
0
        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()));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
 public GenericTypeDefinition(Type type, GenericSaveId saveId)
     : base(type, (SaveId)saveId, (IObjectResolver) new DefaultObjectResolver())
 {
 }