Esempio n. 1
0
        /// <summary>
        /// The managed object.
        /// </summary>
        /// <param name="hash">
        /// The hash.
        /// </param>
        /// <param name="pObj">
        /// The p obj.
        /// </param>
        /// <exception cref="FormatException">
        /// </exception>
        /// <exception cref="ArgumentException">
        /// </exception>
        /// <exception cref="FormatException">
        /// </exception>
        public void ManagedObject(uint hash, ref CIwManaged pObj)
        {
            if (this.mode == IwSerialiseMode.Read)
            {
                IwClassFactory factory = this.ClassRegistry.Get(hash);
                if (factory == null)
                {
                    throw new FormatException(string.Format("Can't Serialise unknown type 0x{0:x}", hash));
                }

                pObj = factory.Create();
            }
            else
            {
                if (hash != pObj.Hash)
                {
                    throw new ArgumentException();
                }
            }

            try
            {
                pObj.Serialise(this);
            }
            catch (Exception ex)
            {
                throw new FormatException(
                          string.Format("Can't Serialise GetResHashed(0x{0:x}, \"0x{1}\")", pObj.Hash, pObj.GetType().Name), ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The managed object.
        /// </summary>
        /// <param name="pObj">
        /// The p obj.
        /// </param>
        /// <exception cref="FormatException">
        /// </exception>
        public void ManagedObject(ref CIwManaged pObj)
        {
            if (this.mode == IwSerialiseMode.Read)
            {
                uint hash = 0;
                this.UInt32(ref hash);
                IwClassFactory factory = this.ClassRegistry.Get(hash);
                if (factory == null)
                {
                    throw new FormatException(string.Format("Can't Serialise unknown type 0x{0:x}", hash));
                }

                pObj = factory.Create();
            }
            else
            {
                uint hash = pObj.Hash;
                this.UInt32(ref hash);
            }

            Debug.WriteLine(string.Format("Serialise {0}", pObj.GetType().Name));
            pObj.Serialise(this);
        }