public override List <uint> Load(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Gibbed.Spore.Properties.Property> properties)
        {
            List <uint> definedProperties = new List <uint>();
            object      list = property.PropertyType.GetConstructor(new Type[] { }).Invoke(new object[] { });

            property.SetValue(file, list, null);

            Type listItemType = property.PropertyType.GetGenericArguments()[0];

            Property listInstance = (Property)listItemType.GetConstructor(new Type[] { }).Invoke(new object[] { });

            if (properties.ContainsKey(this.PropertyID))
            {
                int count = ((ArrayProperty)properties[this.PropertyID]).Values.Count;
                for (int i = 0; i < count; i++)
                {
                    list.GetType().GetMethod("Add").Invoke(list, new object[] { ((ArrayProperty)properties[this.PropertyID]).Values[i] });
                }
            }
            else if (!this.Optional)
            {
                throw new Exception(string.Format("Missing property {0:X8} in property file!", this.PropertyID));
            }
            definedProperties.Add(this.PropertyID);

            return(definedProperties);
        }
        public override void Save(PropertyFileObject file, System.Reflection.PropertyInfo property, Dictionary <uint, Gibbed.Spore.Properties.Property> returnValues)
        {
            Array array         = (Array)property.GetValue(file, null);
            Type  arrayItemType = array.GetType().GetElementType();

            for (int i = 0; i < this.Count; i++)
            {
                IEnumerable <object> list = (IEnumerable <object>)array.GetValue(i);
                //must be based on List<PropertyFileObject>
                Type listItemType = property.PropertyType.GetGenericArguments()[0];
                List <PropertyInfo> listItemProperties = listItemType.GetProperties().Where(p => p.GetCustomAttributes(typeof(PropertyFilePropertyArrayAttribute), false).Count() == 1).ToList <PropertyInfo>();
                int index = 0;

                foreach (PropertyFileObject obj in list)
                {
                    foreach (PropertyInfo listItemProperty in listItemProperties)
                    {
                        PropertyFilePropertyArrayAttribute listItemAttr = (PropertyFilePropertyArrayAttribute)listItemProperty.GetCustomAttributes(typeof(PropertyFilePropertyArrayAttribute), false)[0];
                        if (!returnValues.ContainsKey(listItemAttr.PropertyIDs[i]))
                        {
                            returnValues.Add(listItemAttr.PropertyIDs[i], new ArrayProperty()
                            {
                                Values = new List <Property>(), PropertyType = listItemProperty.PropertyType
                            });
                        }
                        ((ArrayProperty)returnValues[listItemAttr.PropertyIDs[i]]).Values.Add((Property)listItemProperty.GetValue(obj, null));
                    }

                    index++;
                }
            }
        }
Exemplo n.º 3
0
 public override void Save(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> returnValues)
 {
     if (property.GetValue(file, null) != null)
     {
         returnValues.Add(this.PropertyID, (Property)property.GetValue(file, null));
     }
     else if (!this.Optional)
     {
         throw new Exception("Missing property in property file!");
     }
 }
Exemplo n.º 4
0
        public override List <uint> Load(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> properties)
        {
            List <uint> definedProperties = new List <uint>();
            object      list = property.PropertyType.GetConstructor(new Type[] { }).Invoke(new object[] { });

            property.SetValue(file, list, null);
            //must be based on List<PropertyFileObject>
            Type listItemType = property.PropertyType.GetGenericArguments()[0];
            List <PropertyInfo> listItemProperties = listItemType.GetProperties().Where(p => p.GetCustomAttributes(typeof(PropertyFilePropertyAttribute), false).Count() == 1).ToList <PropertyInfo>();

            int index    = 0;
            int maxIndex = int.MaxValue;

            while (index < maxIndex)
            {
                PropertyFileObject listInstance = (PropertyFileObject)listItemType.GetConstructor(new Type[] { }).Invoke(new object[] { });
                bool containsProperty           = false;
                foreach (PropertyInfo listItemProperty in listItemProperties)
                {
                    PropertyFilePropertyAttribute listItemAttr = (PropertyFilePropertyAttribute)listItemProperty.GetCustomAttributes(typeof(PropertyFilePropertyAttribute), false)[0];
                    if (properties.ContainsKey(listItemAttr.PropertyID))
                    {
                        maxIndex = ((ArrayProperty)properties[listItemAttr.PropertyID]).Values.Count;
                        listItemProperty.SetValue(listInstance, ((ArrayProperty)properties[listItemAttr.PropertyID]).Values[index], null);
                        containsProperty = true;
                    }
                    else if (!listItemAttr.Optional)
                    {
                        if (index == 0) //the array may be empty, which could still be valid
                        {
                        }
                        else
                        {
                            throw new Exception(string.Format("Missing property {0:X8} in property file!", listItemAttr.PropertyID));
                        }
                    }
                    definedProperties.Add(listItemAttr.PropertyID);
                }
                if (containsProperty)
                {
                    list.GetType().GetMethod("Add").Invoke(list, new object[] { listInstance });
                }
                else
                {
                    break;
                }

                index++;
            }
            return(definedProperties);
        }
Exemplo n.º 5
0
        public override List <uint> Load(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> properties)
        {
            List <uint> definedProperties = new List <uint>();

            if (properties.ContainsKey(this.PropertyID))
            {
                property.SetValue(file, properties[this.PropertyID], null);
            }
            else if (!this.Optional)
            {
                throw new Exception(string.Format("Missing property {0:X8} in property file!", this.PropertyID));
            }
            definedProperties.Add(this.PropertyID);
            return(definedProperties);
        }
        public override void Save(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Gibbed.Spore.Properties.Property> returnValues)
        {
            IEnumerable <object> list = (IEnumerable <object>)property.GetValue(file, null);
            Type listItemType         = property.PropertyType.GetGenericArguments()[0];

            foreach (Property obj in list)
            {
                if (!returnValues.ContainsKey(this.PropertyID))
                {
                    returnValues.Add(this.PropertyID, new ArrayProperty()
                    {
                        Values = new List <Property>(), PropertyType = listItemType
                    });
                }
                ((ArrayProperty)returnValues[this.PropertyID]).Values.Add(obj);
            }
        }
Exemplo n.º 7
0
        public override void Save(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> returnValues)
        {
            IEnumerable <object> list = (IEnumerable <object>)property.GetValue(file, null);
            //must be based on List<PropertyFileObject>
            Type listItemType = property.PropertyType.GetGenericArguments()[0];
            List <PropertyInfo> listItemProperties = listItemType.GetProperties().Where(p => p.GetCustomAttributes(typeof(PropertyFilePropertyAttribute), false).Count() == 1).ToList <PropertyInfo>();

            foreach (PropertyFileObject obj in list)
            {
                foreach (PropertyInfo listItemProperty in listItemProperties)
                {
                    PropertyFilePropertyAttribute listItemAttr = (PropertyFilePropertyAttribute)listItemProperty.GetCustomAttributes(typeof(PropertyFilePropertyAttribute), false)[0];
                    if (!returnValues.ContainsKey(listItemAttr.PropertyID))
                    {
                        returnValues.Add(listItemAttr.PropertyID, new ArrayProperty()
                        {
                            Values = new List <Property>(), PropertyType = listItemProperty.PropertyType
                        });
                    }
                    ((ArrayProperty)returnValues[listItemAttr.PropertyID]).Values.Add((Property)listItemProperty.GetValue(obj, null));
                }
            }
        }
Exemplo n.º 8
0
 public override List <uint> Load(PropertyFileObject file, System.Reflection.PropertyInfo property, Dictionary <uint, Gibbed.Spore.Properties.Property> properties)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public override void Save(PropertyFileObject file, System.Reflection.PropertyInfo property, Dictionary <uint, Gibbed.Spore.Properties.Property> returnValues)
 {
     throw new NotImplementedException();
 }
        public override List <uint> Load(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> properties)
        {
            //get the properties that exist in arrays with multiple levels
            List <uint> definedProperties = new List <uint>();

            //make a nested list of lists
            object list = property.PropertyType.GetConstructor(new Type[] { typeof(Int32) }).Invoke(new object[] { this.Count }); //this creates the containing array[] of lists

            property.SetValue(file, list, null);

            PropertyFileObjectCollectionArrayAttribute arrayPropAttribute = (PropertyFileObjectCollectionArrayAttribute)property.GetCustomAttributes(typeof(PropertyFileObjectCollectionArrayAttribute), false)[0];
            Array listArray = list as Array;

            for (int i = 0; i < arrayPropAttribute.Count; i++)
            {
                //make a list of lists -
                Type innerListType = listArray.GetType().GetElementType();
                //make an inner list instance
                object innerList = innerListType.GetConstructor(new Type[] { }).Invoke(new object[] { }); //this creates the containing array[] of lists
                listArray.SetValue(innerList, i);

                //must be based on List<PropertyFileObject>
                Type listItemType = innerListType.GetGenericArguments()[0];
                List <PropertyInfo> listItemProperties = listItemType.GetProperties().Where(p => p.GetCustomAttributes(typeof(PropertyFilePropertyArrayAttribute), false).Count() == 1).ToList <PropertyInfo>();

                int index    = 0;
                int maxIndex = int.MaxValue;

                while (index < maxIndex)
                {
                    PropertyFileObject listInstance = (PropertyFileObject)listItemType.GetConstructor(new Type[] { }).Invoke(new object[] { });
                    bool containsProperty           = false;
                    foreach (PropertyInfo listItemProperty in listItemProperties)
                    {
                        PropertyFilePropertyArrayAttribute listItemAttr = (PropertyFilePropertyArrayAttribute)listItemProperty.GetCustomAttributes(typeof(PropertyFilePropertyArrayAttribute), false)[0];
                        if (properties.ContainsKey(listItemAttr.PropertyIDs[i]))
                        {
                            maxIndex = ((ArrayProperty)properties[listItemAttr.PropertyIDs[i]]).Values.Count;
                            listItemProperty.SetValue(listInstance, ((ArrayProperty)properties[listItemAttr.PropertyIDs[i]]).Values[index], null);
                            containsProperty = true;
                        }
                        else if (!listItemAttr.Optional)
                        {
                            if (index == 0) //the array may be empty, which could still be valid
                            {
                            }
                            else
                            {
                                throw new Exception(string.Format("Missing property {0:X8} in property file!", listItemAttr.PropertyIDs[i]));
                            }
                        }
                        definedProperties.Add(listItemAttr.PropertyIDs[i]);
                    }
                    if (containsProperty)
                    {
                        innerList.GetType().GetMethod("Add").Invoke(innerList, new object[] { listInstance });
                    }
                    else
                    {
                        break;
                    }

                    index++;
                }
            }
            return(definedProperties);
        }
Exemplo n.º 11
0
 public abstract List <uint> Load(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> properties);
Exemplo n.º 12
0
 public abstract void Save(PropertyFileObject file, PropertyInfo property, Dictionary <uint, Property> returnValues);