public static void UmaReadWriteStructArray_InsufficientSpace()
 {
     const int capacity = 100;
     UmaTestStruct[] structArr = new UmaTestStruct[1];
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         Assert.Throws<ArgumentException>(() => uma.WriteArray<UmaTestStruct>(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1));
         Assert.Throws<ArgumentException>(() => uma.WriteArray<UmaTestStruct>(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1));
         Assert.Equal(0, uma.ReadArray<UmaTestStruct>(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1));
         Assert.Equal(0, uma.ReadArray<UmaTestStruct>(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1));
     }
 }
        public static void UmaReadWriteStructArray_InsufficientSpace()
        {
            const int capacity = 100;

            UmaTestStruct[] structArr = new UmaTestStruct[1];
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.WriteArray <UmaTestStruct>(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.WriteArray <UmaTestStruct>(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1));
                    Assert.Equal(0, uma.ReadArray <UmaTestStruct>(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1));
                    Assert.Equal(0, uma.ReadArray <UmaTestStruct>(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1));
                }
        }
        public static void UmaReadWriteStructArray_Multiples()
        {
            const int numberOfStructs = 12;
            const int capacity        = numberOfStructs * UmaTestStruct_AlignedSize;

            UmaTestStruct[] inStructArr  = new UmaTestStruct[numberOfStructs];
            UmaTestStruct[] outStructArr = new UmaTestStruct[numberOfStructs];
            for (int i = 0; i < numberOfStructs; i++)
            {
                inStructArr[i] = new UmaTestStruct()
                {
                    bool1 = false, bool2 = true, int1 = i, int2 = i + 1, char1 = (char)i
                };
            }
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    uma.WriteArray <UmaTestStruct>(0, inStructArr, 0, numberOfStructs);
                    Assert.Equal(numberOfStructs, uma.ReadArray <UmaTestStruct>(0, outStructArr, 0, numberOfStructs));
                    for (int i = 0; i < numberOfStructs; i++)
                    {
                        Assert.Equal(i, outStructArr[i].int1);
                        Assert.Equal(i + 1, outStructArr[i].int2);
                        Assert.Equal(false, outStructArr[i].bool1);
                        Assert.Equal((char)i, outStructArr[i].char1);
                        Assert.Equal(true, outStructArr[i].bool2);
                    }
                }
        }
Beispiel #4
0
        public static T[] ReadArray <T>(this UnmanagedMemoryAccessor reader, int count, ref int index) where T : struct
        {
            var result = new T[count];

            reader.ReadArray(index, result, 0, count);
            index += Marshal.SizeOf(typeof(T)) * count;
            return(result);
        }
        private static string ReadKey(UnmanagedMemoryAccessor reader, int size)
        {
            var buffer = new byte[size];

            reader.ReadArray(0, buffer, 0, size);

            return(Encoding.UTF8.GetString(buffer));
        }
 public static void UmaReadStructArray_WriteMode()
 {
     const int capacity = 100;
     UmaTestStruct[] structArr = new UmaTestStruct[1];
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.Write))
     {
         Assert.Throws<NotSupportedException>(() => uma.ReadArray<UmaTestStruct>(0, structArr, 0, 1));
     }
 }
        public static Byte[] ReadBuffer(this UnmanagedMemoryAccessor memoryAccessor)
        {
            Verify.NotNull(memoryAccessor, "memoryAccessor");

            var result = new Byte[memoryAccessor.Capacity];

            memoryAccessor.ReadArray(0, result, 0, result.Length);

            return(result);
        }
        public static void UmaReadStructArray_WriteMode()
        {
            const int capacity = 100;

            UmaTestStruct[] structArr = new UmaTestStruct[1];
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.Write))
                {
                    Assert.Throws <NotSupportedException>(() => uma.ReadArray <UmaTestStruct>(0, structArr, 0, 1));
                }
        }
Beispiel #9
0
        /// <summary></summary>
        /// <param name="accessor"></param>
        /// <param name="position"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static Byte[] ReadArray(this UnmanagedMemoryAccessor accessor, Int32 position, Int32 count)
        {
            var buf = new Byte[count];
            var n   = accessor.ReadArray(position, buf, 0, buf.Length);

            if (n <= buf.Length)
            {
                buf = buf.ReadBytes(0, n);
            }

            return(buf);
        }
 public static void UmaReadWriteStructArray_Closed()
 {
     const int capacity = 100;
     UmaTestStruct[] structArr = new UmaTestStruct[1];
     using (var buffer = new TestSafeBuffer(capacity))
     {
         UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite);
         uma.Dispose();
         Assert.Throws<ObjectDisposedException>(() => uma.WriteArray<UmaTestStruct>(0, structArr, 0, 1));
         Assert.Throws<ObjectDisposedException>(() => uma.ReadArray<UmaTestStruct>(0, structArr, 0, 1));
     }
 }
Beispiel #11
0
        public static T[] ReadArray <T>(
            this UnmanagedMemoryAccessor accessor, long position, int availableLength)
            where T : struct
        {
            var count  = availableLength / Marshal.SizeOf <T>();
            var values = new T[count];

            if (accessor.ReadArray(position, values, 0, count) != count)
            {
                throw new EndOfStreamException();
            }
            return(values);
        }
        public static void UmaReadWriteStructArray_Closed()
        {
            const int capacity = 100;

            UmaTestStruct[] structArr = new UmaTestStruct[1];
            using (var buffer = new TestSafeBuffer(capacity))
            {
                UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite);
                uma.Dispose();
                Assert.Throws <ObjectDisposedException>(() => uma.WriteArray <UmaTestStruct>(0, structArr, 0, 1));
                Assert.Throws <ObjectDisposedException>(() => uma.ReadArray <UmaTestStruct>(0, structArr, 0, 1));
            }
        }
Beispiel #13
0
        /// <summary>
        /// Extends ReadArray<T> so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// unmanagedmemoryaccessor.ReadArray<T>(position, array);
        /// </example>
        /// </summary>
        public static Int32 ReadArray <T>(this UnmanagedMemoryAccessor unmanagedmemoryaccessor, Int64 position, T[] array) where T : struct
        {
            if (unmanagedmemoryaccessor == null)
            {
                throw new ArgumentNullException("unmanagedmemoryaccessor");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            return(unmanagedmemoryaccessor.ReadArray(position, array, 0, array.Length));
        }
        public static void UmaReadWriteStructArray_InvalidParameters()
        {
            const int capacity = 100;

            UmaTestStruct[] structArr = new UmaTestStruct[1];
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    AssertExtensions.Throws <ArgumentNullException>("array", () => uma.WriteArray <UmaTestStruct>(0, null, 0, 1));
                    AssertExtensions.Throws <ArgumentNullException>("array", () => uma.ReadArray <UmaTestStruct>(0, null, 0, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("offset", () => uma.WriteArray <UmaTestStruct>(0, structArr, -1, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("offset", () => uma.ReadArray <UmaTestStruct>(0, structArr, -1, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("count", () => uma.WriteArray <UmaTestStruct>(0, structArr, 0, -1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("count", () => uma.ReadArray <UmaTestStruct>(0, structArr, 0, -1));
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.WriteArray <UmaTestStruct>(0, structArr, 2, 0));
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.ReadArray <UmaTestStruct>(0, structArr, 2, 0));
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.WriteArray <UmaTestStruct>(0, structArr, 0, 2));
                    AssertExtensions.Throws <ArgumentException>(null, () => uma.ReadArray <UmaTestStruct>(0, structArr, 0, 2));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("position", () => uma.WriteArray <UmaTestStruct>(-1, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("position", () => uma.ReadArray <UmaTestStruct>(-1, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("position", () => uma.WriteArray <UmaTestStruct>(capacity, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentOutOfRangeException>("position", () => uma.ReadArray <UmaTestStruct>(capacity, structArr, 0, 1));
                }
        }
        public static void UmaReadWriteStructArrayWithReferenceType_ThrowsArgumentException()
        {
            const int capacity = 100;

            UmaTestStruct_ContainsReferenceType[] structArr = new UmaTestStruct_ContainsReferenceType[1] {
                new UmaTestStruct_ContainsReferenceType()
                {
                    referenceType = new object()
                }
            };
            using (var buffer = new TestSafeBuffer(capacity))
                using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    AssertExtensions.Throws <ArgumentException>("type", () => uma.WriteArray <UmaTestStruct_ContainsReferenceType>(0, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentException>("type", () => uma.ReadArray <UmaTestStruct_ContainsReferenceType>(0, structArr, 0, 1));
                }
        }
        public static void UmaReadWriteGenericStringStructArray_ThrowsArgumentException()
        {
            const int capacity = 100;

            UmaTestStruct_Generic <string>[] structArr = new UmaTestStruct_Generic <string>[1] {
                new UmaTestStruct_Generic <string>()
                {
                    ofT = "Cats!"
                }
            };
            using (var buffer = new TestSafeBuffer(capacity))
                using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    AssertExtensions.Throws <ArgumentException>("type", () => uma.WriteArray <UmaTestStruct_Generic <string> >(0, structArr, 0, 1));
                    AssertExtensions.Throws <ArgumentException>("type", () => uma.ReadArray <UmaTestStruct_Generic <string> >(0, structArr, 0, 1));
                }
        }
        public static void UmaReadWriteStructArrayGenericIntStruct_Valid()
        {
            const int capacity = 100;

            UmaTestStruct_Generic <int>[] inStructArr = new UmaTestStruct_Generic <int>[1] {
                new UmaTestStruct_Generic <int>()
                {
                    ofT = 190
                }
            };
            UmaTestStruct_Generic <int>[] outStructArr = new UmaTestStruct_Generic <int> [1];
            using (var buffer = new TestSafeBuffer(capacity))
                using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    uma.WriteArray <UmaTestStruct_Generic <int> >(0, inStructArr, 0, 1);
                    Assert.Equal(1, uma.ReadArray <UmaTestStruct_Generic <int> >(0, outStructArr, 0, 1));
                    Assert.Equal(inStructArr[0].ofT, outStructArr[0].ofT);
                }
        }
        public static void UmaReadWriteStructArray_TryToReadMoreThanAvailable()
        {
            const int capacity = 100;

            UmaTestStruct[] inStructArr = new UmaTestStruct[1] {
                new UmaTestStruct()
                {
                    int1 = 1, int2 = 2, bool1 = false, char1 = 'p', bool2 = true
                }
            };
            UmaTestStruct[] outStructArr = new UmaTestStruct[5000];
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    uma.WriteArray <UmaTestStruct>(0, inStructArr, 0, 1);
                    int readCount = uma.ReadArray <UmaTestStruct>(0, outStructArr, 0, 5000);
                    Assert.Equal(capacity / UmaTestStruct_AlignedSize, readCount);
                }
        }
        public static void UmaReadWriteStructArray_OneItem()
        {
            const int capacity = 100;

            UmaTestStruct[] inStructArr = new UmaTestStruct[1] {
                new UmaTestStruct()
                {
                    int1 = 1, int2 = 2, bool1 = false, char1 = 'p', bool2 = true
                }
            };
            UmaTestStruct[] outStructArr = new UmaTestStruct[1];
            using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
                using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
                {
                    uma.WriteArray <UmaTestStruct>(capacity - UmaTestStruct_AlignedSize, inStructArr, 0, 1);
                    Assert.Equal(1, uma.ReadArray <UmaTestStruct>(capacity - UmaTestStruct_AlignedSize, outStructArr, 0, 1));
                    Assert.Equal(inStructArr[0].int1, outStructArr[0].int1);
                    Assert.Equal(inStructArr[0].int2, outStructArr[0].int2);
                    Assert.Equal(inStructArr[0].bool1, outStructArr[0].bool1);
                    Assert.Equal(inStructArr[0].char1, outStructArr[0].char1);
                    Assert.Equal(inStructArr[0].bool2, outStructArr[0].bool2);
                }
        }
 public static void UmaReadWriteStructArray_InvalidParameters()
 {
     const int capacity = 100;
     UmaTestStruct[] structArr = new UmaTestStruct[1];
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         Assert.Throws<ArgumentNullException>("array", () => uma.WriteArray<UmaTestStruct>(0, null, 0, 1));
         Assert.Throws<ArgumentNullException>("array", () => uma.ReadArray<UmaTestStruct>(0, null, 0, 1));
         Assert.Throws<ArgumentOutOfRangeException>("offset", () => uma.WriteArray<UmaTestStruct>(0, structArr, -1, 1));
         Assert.Throws<ArgumentOutOfRangeException>("offset", () => uma.ReadArray<UmaTestStruct>(0, structArr, -1, 1));
         Assert.Throws<ArgumentOutOfRangeException>("count", () => uma.WriteArray<UmaTestStruct>(0, structArr, 0, -1));
         Assert.Throws<ArgumentOutOfRangeException>("count", () => uma.ReadArray<UmaTestStruct>(0, structArr, 0, -1));
         Assert.Throws<ArgumentException>(() => uma.WriteArray<UmaTestStruct>(0, structArr, 2, 0));
         Assert.Throws<ArgumentException>(() => uma.ReadArray<UmaTestStruct>(0, structArr, 2, 0));
         Assert.Throws<ArgumentException>(() => uma.WriteArray<UmaTestStruct>(0, structArr, 0, 2));
         Assert.Throws<ArgumentException>(() => uma.ReadArray<UmaTestStruct>(0, structArr, 0, 2));
         Assert.Throws<ArgumentOutOfRangeException>("position", () => uma.WriteArray<UmaTestStruct>(-1, structArr, 0, 1));
         Assert.Throws<ArgumentOutOfRangeException>("position", () => uma.ReadArray<UmaTestStruct>(-1, structArr, 0, 1));
         Assert.Throws<ArgumentOutOfRangeException>("position", () => uma.WriteArray<UmaTestStruct>(capacity, structArr, 0, 1));
         Assert.Throws<ArgumentOutOfRangeException>("position", () => uma.ReadArray<UmaTestStruct>(capacity, structArr, 0, 1));
     }
 }
 public static void UmaReadWriteGenericStringStructArray_ThrowsArgumentException()
 {
     const int capacity = 100;
     UmaTestStruct_Generic<string>[] structArr = new UmaTestStruct_Generic<string>[1] { new UmaTestStruct_Generic<string>() { ofT = "Cats!" } };
     using (var buffer = new TestSafeBuffer(capacity))
     using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         Assert.Throws<ArgumentException>("type", () => uma.WriteArray<UmaTestStruct_Generic<string>>(0, structArr, 0, 1));
         Assert.Throws<ArgumentException>("type", () => uma.ReadArray<UmaTestStruct_Generic<string>>(0, structArr, 0, 1));
     }
 }
 public static void UmaReadWriteStructArray_Multiples()
 {
     const int numberOfStructs = 12;
     const int capacity = numberOfStructs * UmaTestStruct_AlignedSize;
     UmaTestStruct[] inStructArr = new UmaTestStruct[numberOfStructs];
     UmaTestStruct[] outStructArr = new UmaTestStruct[numberOfStructs];
     for (int i = 0; i < numberOfStructs; i++)
     {
         inStructArr[i] = new UmaTestStruct() { bool1 = false, bool2 = true, int1 = i, int2 = i + 1, char1 = (char)i };
     }
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         uma.WriteArray<UmaTestStruct>(0, inStructArr, 0, numberOfStructs);
         Assert.Equal(numberOfStructs, uma.ReadArray<UmaTestStruct>(0, outStructArr, 0, numberOfStructs));
         for (int i = 0; i < numberOfStructs; i++)
         {
             Assert.Equal(i, outStructArr[i].int1);
             Assert.Equal(i+1, outStructArr[i].int2);
             Assert.Equal(false, outStructArr[i].bool1);
             Assert.Equal((char)i, outStructArr[i].char1);
             Assert.Equal(true, outStructArr[i].bool2);
         }
     }
 }
 public static void UmaReadWriteStructArrayWithReferenceType_ThrowsArgumentException()
 {
     const int capacity = 100;
     UmaTestStruct_ContainsReferenceType[] structArr = new UmaTestStruct_ContainsReferenceType[1] { new UmaTestStruct_ContainsReferenceType() { referenceType = new object() } };
     using (var buffer = new TestSafeBuffer(capacity))
     using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         Assert.Throws<ArgumentException>("type", () => uma.WriteArray<UmaTestStruct_ContainsReferenceType>(0, structArr, 0, 1));
         Assert.Throws<ArgumentException>("type", () => uma.ReadArray<UmaTestStruct_ContainsReferenceType>(0, structArr, 0, 1));
     }
 }
 public static void UmaReadWriteStructArray_OneItem()
 {
     const int capacity = 100;
     UmaTestStruct[] inStructArr = new UmaTestStruct[1] { new UmaTestStruct() { int1 = 1, int2 = 2, bool1 = false, char1 = 'p', bool2 = true } };
     UmaTestStruct[] outStructArr = new UmaTestStruct[1];
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         uma.WriteArray<UmaTestStruct>(capacity - UmaTestStruct_AlignedSize, inStructArr, 0, 1);
         Assert.Equal(1, uma.ReadArray<UmaTestStruct>(capacity - UmaTestStruct_AlignedSize, outStructArr, 0, 1));
         Assert.Equal(inStructArr[0].int1, outStructArr[0].int1);
         Assert.Equal(inStructArr[0].int2, outStructArr[0].int2);
         Assert.Equal(inStructArr[0].bool1, outStructArr[0].bool1);
         Assert.Equal(inStructArr[0].char1, outStructArr[0].char1);
         Assert.Equal(inStructArr[0].bool2, outStructArr[0].bool2);
     }
 }
Beispiel #25
0
        private bool LoadRecordValue(
            ThemeFile theme, VSRecord record,
            UnmanagedMemoryAccessor data, long offset, out object value)
        {
            TPID id = GetThemePrimitiveId(record.SymbolVal, record.Type);

            if (id == TPID.Invalid)
            {
                value = null;
                return(false);
            }

            if (record.ResId == 0)
            {
                var payload = new byte[record.ByteLength];
                data.ReadArray(offset, payload, 0, payload.Length);

                switch (id)
                {
                case TPID.STRING:
                    value = data.ReadZString(offset);
                    return(true);

                case TPID.ENUM:
                    value = GetEnum(data.ReadInt32(offset), (TMT)record.SymbolVal);
                    return(true);

                case TPID.BOOL:
                    value = data.ReadInt32(offset) == 1;
                    return(true);

                case TPID.INT:
                    value = data.ReadInt32(offset);
                    return(true);

                case TPID.COLOR:
                    value = ColorUtils.ColorFromCOLORREF(data.ReadInt32(offset));
                    return(true);

                case TPID.MARGINS:
                    value = data.Read <MARGINS>(offset);
                    return(true);

                case TPID.SIZE:
                    value = data.ReadInt32(offset);
                    return(true);

                case TPID.POSITION:
                    value = data.Read <POINT>(offset);
                    return(true);

                case TPID.RECT:
                    value = data.Read <RECT>(offset);
                    return(true);

                case TPID.HIGHCONTRASTCOLORTYPE:
                    value = (HIGHCONTRASTCOLOR)data.ReadInt32(offset);
                    return(true);

                case TPID.SIMPLIFIEDIMAGETYPE:
                    if (record.SymbolVal == (int)TMT.HCSIMPLIFIEDIMAGE)
                    {
                        value = data.ReadArray <HCIMAGEPROPERTIES>(offset, record.ByteLength);
                    }
                    else
                    {
                        value = data.ReadArray <IMAGEPROPERTIES>(offset, record.ByteLength);
                    }
                    return(true);

                case TPID.INTLIST:
                    int length = data.ReadInt32(offset);
                    if (length <= 1)
                    {
                        value = new IntList(new int[0]);
                        return(true);
                    }

                    int dim = data.ReadInt32(offset + 4);
                    Debug.Assert(length - 1 == dim * dim);
                    var intList = new int[length - 1];
                    data.ReadArray(offset + 8, intList, 0, intList.Length);
                    value = new IntList(intList);
                    return(true);

                default:
                    Console.WriteLine($"Unprocessed resource property type {id}");
                    value = null;
                    return(false);
                }
            }
            else
            {
                value = null;
                switch (id)
                {
                case TPID.BITMAPIMAGE1:
                case TPID.BITMAPIMAGE2:
                case TPID.BITMAPIMAGE3:
                case TPID.BITMAPIMAGE4:
                case TPID.BITMAPIMAGE5:
                case TPID.BITMAPIMAGE6:
                case TPID.BITMAPIMAGE7:
                case TPID.STOCKBITMAPIMAGE:
                case TPID.GLYPHIMAGE:
                case TPID.COMPOSEDIMAGETYPE:
                    return(LoadImageFileRes(theme.Theme, record.ResId, out value));

                // TPID_ATLASIMAGE
                // TPID_ATLASINPUTIMAGE
                // TPID_ENUM
                case TPID.STRING:
                    return(LoadStringRes(theme.MUI, record.ResId, out value));

                // TPID_INT
                case TPID.BOOL:
                    return(LoadBoolRes(theme.MUI, record.ResId, out value));

                // TPID_COLOR
                // TPID_MARGINS
                case TPID.FILENAME:
                    if (IsImageFile((TMT)record.SymbolVal))
                    {
                        return(LoadImageFileRes(theme.Theme, record.ResId, out value));
                    }
                    return(LoadStringRes(theme.MUI, record.ResId, out value));

                // TPID_SIZE
                // TPID_POSITION
                case TPID.RECT:
                    return(LoadRectRes(theme.MUI, record.ResId, out value));

                case TPID.FONT:
                    return(LoadFontRes(theme.MUI, record.ResId, out value));

                case TPID.DISKSTREAM:
                    value = "DISKSTREAM(" + record.ResId + ", len=" + record.ByteLength + ")";
                    //var window = new Form();
                    //window.ShowDialog();
                    //var th = StyleNativeMethods.OpenThemeData(
                    //    window.Handle, "LISTVIEW");

                    //IntPtr stream;
                    //uint streamLen;
                    //HResult hr = StyleNativeMethods.GetThemeStream(
                    //    th, (int)header.Part, (int)header.State, (int)header.Property,
                    //    out stream, out streamLen, tf.hTheme);

                    //th.Dispose();

                    //GC.KeepAlive(window);
                    return(true);

                default:
                    Console.WriteLine($"Unprocessed MUI resource property type {id}");
                    return(false);
                }
            }
        }
 public static void UmaReadWriteStructArrayGenericIntStruct_Valid()
 {
     const int capacity = 100;
     UmaTestStruct_Generic<int>[] inStructArr = new UmaTestStruct_Generic<int>[1] { new UmaTestStruct_Generic<int>() { ofT = 190 } };
     UmaTestStruct_Generic<int>[] outStructArr = new UmaTestStruct_Generic<int>[1];
     using (var buffer = new TestSafeBuffer(capacity))
     using (var uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         uma.WriteArray<UmaTestStruct_Generic<int>>(0, inStructArr, 0, 1);
         Assert.Equal(1, uma.ReadArray<UmaTestStruct_Generic<int>>(0, outStructArr, 0, 1));
         Assert.Equal(inStructArr[0].ofT, outStructArr[0].ofT);
     }
 }
 public static void UmaReadWriteStructArray_TryToReadMoreThanAvailable()
 {
     const int capacity = 100;
     UmaTestStruct[] inStructArr = new UmaTestStruct[1] { new UmaTestStruct() { int1 = 1, int2 = 2, bool1 = false, char1 = 'p', bool2 = true } };
     UmaTestStruct[] outStructArr = new UmaTestStruct[5000];
     using (TestSafeBuffer buffer = new TestSafeBuffer(capacity))
     using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite))
     {
         uma.WriteArray<UmaTestStruct>(0, inStructArr, 0, 1);
         int readCount = uma.ReadArray<UmaTestStruct>(0, outStructArr, 0, 5000);
         Assert.Equal(capacity / UmaTestStruct_AlignedSize, readCount);
     }
 }