예제 #1
0
        /// <summary>
        /// Deserializes the last serialized struct array, loading the structs back into TheStructs.
        /// </summary>
        public void Deserialize()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            // clear the old list
            TheStructs.Clear();
            for (int i = 0; i < SerializedCount.Value; ++i)
            {
                var thisStructPtr = IntPtr.Add(PointerToFirstStruct, i * StructSize.Value);
                TheStructs.Add((T)Marshal.PtrToStructure(thisStructPtr, typeof(T)));
            }
        }
예제 #2
0
        /// <summary>
        /// Deserializes the last serialized struct array, loading the structs back into TheStructs.
        /// </summary>
        public void Deserialize()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            // clear the old list
            TheStructs.Clear();

            foreach (var structPointer in StructPointers)
            {
                TheStructs.Add((T)Marshal.PtrToStructure(structPointer, typeof(T)));
            }
        }
예제 #3
0
        /// <summary>
        /// Deserializes a different struct array, loading the structs into TheStructs. Other public-facing
        /// properties remain untouched.
        /// </summary>
        public void Deserialize(int count, IntPtr pointerToContiguousStructs)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            var oneSize = Marshal.SizeOf(typeof(T));

            TheStructs.Clear();
            for (int i = 0; i < count; ++i)
            {
                var thisStructPtr = IntPtr.Add(pointerToContiguousStructs, i * oneSize);
                TheStructs.Add((T)Marshal.PtrToStructure(thisStructPtr, typeof(T)));
            }
        }
예제 #4
0
        /// <summary>
        /// Deserializes a different struct array, loading the structs into TheStructs. Other public-facing
        /// properties remain untouched.
        /// </summary>
        public void Deserialize(int count, IntPtr pointerToStructPointers)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            var localStructPointers = new IntPtr[count];

            Marshal.Copy(pointerToStructPointers, localStructPointers, 0, count);

            TheStructs.Clear();
            foreach (var structPointer in localStructPointers)
            {
                TheStructs.Add((T)Marshal.PtrToStructure(structPointer, typeof(T)));
            }
        }