Beispiel #1
0
        public static LinkedIndexItem <T> FromArray(byte[] bytes)
        {
            BinaryReader        reader = new BinaryReader(new MemoryStream(bytes));
            LinkedIndexItem <T> s      = default(LinkedIndexItem <T>);

            s.Content      = ConverterHelper.FromBytes <T>(reader.ReadBytes(SizeHelper.SizeOf(typeof(T))));
            s.PreviousItem = reader.ReadInt32();

            return(s);
        }
Beispiel #2
0
        public static byte[] GetBytes(object str)
        {
            int size = SizeHelper.SizeOf(str.GetType());

            byte[] arr = new byte[size];

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(str, ptr, true);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }
Beispiel #3
0
        public static T FromBytes <T>(byte[] arr)
            where T : struct
        {
            T str = new T();

            int    size = SizeHelper.SizeOf(typeof(T));
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            Marshal.Copy(arr, 0, ptr, size);

            str = (T)Marshal.PtrToStructure(ptr, str.GetType());
            Marshal.FreeHGlobal(ptr);

            return(str);
        }
Beispiel #4
0
 public Index(string path)
 {
     _typeSize = SizeHelper.SizeOf(typeof(T));
     _stream   = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
 }