Пример #1
0
        public void GetObject()
        {
            var path = Combine(Files.GetExecutingPath(), "Resources", "TestResourceResX.resx");
            var rs   = new ResXResourceSet(path, null);

            // string
            Assert.IsInstanceOf <string>(rs.GetObject("TestString"));
            Assert.IsInstanceOf <string>(rs.GetMetaObject("TestString"));
            Assert.AreNotEqual(rs.GetObject("TestString"), rs.GetMetaObject("TestString"));
            Assert.IsTrue(rs.GetString("MultilineString").Contains(Environment.NewLine), "MultilineString should contain the NewLine string");

            // WinForms.FileRef/string
            Assert.IsInstanceOf <string>(rs.GetObject("TestTextFile"));

            // byte array without mime
            Assert.IsInstanceOf <byte[]>(rs.GetObject("TestBytes"));

            // null stored in the compatible way
            Assert.IsNull(rs.GetObject("TestNull"));

            // no mime, parsed from string by type converter
            Assert.IsInstanceOf <Point>(rs.GetObject("TestPoint"));

#if NETFRAMEWORK
            // mime, deserialized by BinaryFormatter
            Assert.IsInstanceOf <ImageListStreamer>(rs.GetObject("TestObjectEmbedded"));
#endif

#if !NETCOREAPP2_0
            // mime, converted from byte array by type converter
            Assert.IsInstanceOf <Bitmap>(rs.GetObject("TestImageEmbedded"));
#endif

            // WinForms.FileRef/byte[]
            Assert.IsInstanceOf <byte[]>(rs.GetObject("TestBinFile"));

            // WinForms.FileRef/MemoryStream
            Assert.IsInstanceOf <MemoryStream>(rs.GetObject("TestSound"));

#if !NETCOREAPP2_0
            // WinForms.FileRef/object created from stream
            Assert.IsInstanceOf <Bitmap>(rs.GetObject("TestImage"));
#endif
        }