Example #1
0
        /// <summary>
        /// Read the object's package properties by finding its <see cref="PackagePropertyAttribute"/>-assigned properties, and then reading them in order.
        /// </summary>
        /// <param name="target">The object to read.</param>
        /// <param name="package">The <see cref="Package"/> this object is in.</param>
        /// <param name="reader">The <see cref="BinaryReader"/> to read from.</param>
        /// <param name="end">The end position of the object in the stream.</param>
        public static void ReadObject(object target, Package package, BinaryReader reader, long end)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            var targetType = target.GetType();
            var properties = GetNativeProperties(targetType);

            for (var index = 0; index < properties.Count; index++)
            {
                var                      native    = properties[index];
                PropertyInfo             property  = native.Property;
                PackagePropertyAttribute attribute = native.Attribute;
                Type                     type      = property.PropertyType;

                if (reader.BaseStream.Position >= end)
                {
                    throw new InvalidOperationException("The object has read past its end.");
                }

                if (attribute.ExclusiveToGames.Count == 0 || attribute.ExclusiveToGames.Contains(package.Game))
                {
                    object value = attribute.Read(property, target, package, reader, end);
                    property.SetValue(target, value, null);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Initialize the <see cref="PackageProperty"/>.
 /// </summary>
 /// <param name="property">The value for the <see cref="Property"/> field.</param>
 /// <param name="attribute">The value for the <see cref="PackagePropertyAttribute"/> field.</param>
 public PackageProperty(PropertyInfo property, PackagePropertyAttribute attribute)
 {
     Property  = property;
     Attribute = attribute;
 }