Ejemplo 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);
        }
        private bool CheckIfBaseTypeDefind(Type type)
        {
            Type baseType = type.BaseType;
            TypeDefinitionBase typeDefinitionBase = (TypeDefinitionBase)null;

            for (; baseType != (Type)null && baseType != typeof(object); baseType = baseType.BaseType)
            {
                Type type1 = baseType;
                if (baseType.IsGenericType && !baseType.IsGenericTypeDefinition)
                {
                    type1 = baseType.GetGenericTypeDefinition();
                }
                typeDefinitionBase = this._definitionContext.GetTypeDefinition(type1);
                if (typeDefinitionBase != null)
                {
                    break;
                }
            }
            return(typeDefinitionBase != null && !(typeDefinitionBase is BasicTypeDefinition));
        }
 public void CollectProperties()
 {
     foreach (PropertyInfo property in this.Type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     {
         Attribute[] array = property.GetCustomAttributes(typeof(SaveablePropertyAttribute)).ToArray <Attribute>();
         if (array.Length != 0)
         {
             SaveablePropertyAttribute propertyAttribute = (SaveablePropertyAttribute)array[0];
             MemberTypeId       memberTypeId             = new MemberTypeId(TypeDefinitionBase.GetClassLevel(property.DeclaringType), propertyAttribute.LocalSaveId);
             PropertyDefinition propertyDefinition       = new PropertyDefinition(property, memberTypeId);
             if (this._properties.ContainsKey(memberTypeId))
             {
                 this._errors.Add("SaveId " + (object)memberTypeId + " of property " + propertyDefinition.PropertyInfo.Name + " is already defined in type " + this.Type.FullName);
             }
             else
             {
                 this._properties.Add(memberTypeId, propertyDefinition);
                 this.MemberDefinitions.Add((MemberDefinition)propertyDefinition);
             }
         }
     }
 }
 public void CollectFields()
 {
     foreach (FieldInfo fieldInfo in TypeDefinition.GetFieldsOfType(this.Type).ToArray <FieldInfo>())
     {
         Attribute[] array = fieldInfo.GetCustomAttributes(typeof(SaveableFieldAttribute)).ToArray <Attribute>();
         if (array.Length != 0)
         {
             SaveableFieldAttribute saveableFieldAttribute = (SaveableFieldAttribute)array[0];
             MemberTypeId           memberTypeId           = new MemberTypeId(TypeDefinitionBase.GetClassLevel(fieldInfo.DeclaringType), saveableFieldAttribute.LocalSaveId);
             FieldDefinition        fieldDefinition        = new FieldDefinition(fieldInfo, memberTypeId);
             if (this._fields.ContainsKey(memberTypeId))
             {
                 this._errors.Add("SaveId " + (object)memberTypeId + " of field " + (object)fieldDefinition.FieldInfo + " is already defined in type " + this.Type.FullName);
             }
             else
             {
                 this._fields.Add(memberTypeId, fieldDefinition);
                 this.MemberDefinitions.Add((MemberDefinition)fieldDefinition);
             }
         }
     }
     foreach (CustomField customField in this.CustomFields)
     {
         string          name            = customField.Name;
         short           saveId          = customField.SaveId;
         FieldInfo       field           = this.Type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         MemberTypeId    memberTypeId    = new MemberTypeId(TypeDefinitionBase.GetClassLevel(field.DeclaringType), saveId);
         FieldDefinition fieldDefinition = new FieldDefinition(field, memberTypeId);
         if (this._fields.ContainsKey(memberTypeId))
         {
             this._errors.Add("SaveId " + (object)memberTypeId + " of field " + (object)fieldDefinition.FieldInfo + " is already defined in type " + this.Type.FullName);
         }
         else
         {
             this._fields.Add(memberTypeId, fieldDefinition);
             this.MemberDefinitions.Add((MemberDefinition)fieldDefinition);
         }
     }
 }
Ejemplo n.º 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);
        }
        private bool CheckIfPrimitiveOrPrimiteHolderStruct(Type type)
        {
            bool flag = false;
            TypeDefinitionBase typeDefinition1 = this._definitionContext.GetTypeDefinition(type);

            if (typeDefinition1 is BasicTypeDefinition)
            {
                flag = true;
            }
            else if (typeDefinition1 is EnumDefinition)
            {
                flag = true;
            }
            if (!flag && typeDefinition1 is TypeDefinition)
            {
                TypeDefinition typeDefinition2 = (TypeDefinition)typeDefinition1;
                if (!typeDefinition2.IsClassDefinition && !this.CheckIfGotAnyNonPrimitiveMembers(typeDefinition2))
                {
                    flag = true;
                }
            }
            return(flag);
        }
 protected TypeDefinitionBase(Type type, SaveId saveId)
 {
     this.Type      = type;
     this.SaveId    = saveId;
     this.TypeLevel = TypeDefinitionBase.GetClassLevel(type);
 }