Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }