當前位置: 首頁>>代碼示例>>C#>>正文


C# BinarySerializer.Deserialize方法代碼示例

本文整理匯總了C#中BinarySerializer.Deserialize方法的典型用法代碼示例。如果您正苦於以下問題:C# BinarySerializer.Deserialize方法的具體用法?C# BinarySerializer.Deserialize怎麽用?C# BinarySerializer.Deserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinarySerializer的用法示例。


在下文中一共展示了BinarySerializer.Deserialize方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LargeArrayTest

        public void LargeArrayTest()
        {
            var ser = new BinarySerializer();
            var data = new byte[65536 * sizeof(int) * 2];

            ser.Deserialize<IntArray64K>(data);

            using (var ms = new MemoryStream(data))
            {
                ser.Deserialize<IntArray64K>(ms);
            }
        }
開發者ID:andyvans,項目名稱:BinarySerializer,代碼行數:12,代碼來源:LargeArrayTests.cs

示例2: LoadState

        private void LoadState()
        {
            try
            {
                var ser = new BinarySerializer();
                var stat = ser.Deserialize(StateFileName) as Dictionary<String, Object>;

                if (stat != null)
                {
                    var w = (Int32)stat["Width"];
                    var h = (Int32)stat["Height"];

                    if (w > MinimumSize.Width)
                        Width = w;

                    if (h > MinimumSize.Height)
                        Height = h;

                    var x = (Int32)stat["X"];
                    var y = (Int32)stat["Y"];

                    if (x > 0 && y > 0)
                        Location = new Point(x, y);

                    foreach (var p in GetType().GetProperties())
                    {
                        if (Attribute.IsDefined(p, typeof(StateItemAttribute)))
                            p.SetValue(this, stat[p.Name], null);
                    }
                }
            }
            catch { }
        }
開發者ID:rizwan3d,項目名稱:elalang,代碼行數:33,代碼來源:StateForm.cs

示例3: Main

        private static void Main(string[] args)
        {
            var file = args[0];

            using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                var serializer = new BinarySerializer();
                serializer.MemberDeserialized += (sender, eventArgs) => Console.WriteLine(eventArgs.MemberName + " : " + eventArgs.Value);

                var iso = serializer.Deserialize<Iso9660.Iso9660>(stream);
                stream.Position = 0;

                var xmlSerializer = new XmlSerializer(typeof (Iso9660.Iso9660));

                var outfilePath = Path.GetDirectoryName(file);
                var outfileName = Path.GetFileNameWithoutExtension(file) + ".xml";
                var outfile = Path.Combine(outfilePath, outfileName);

                using (var xmlStream = new FileStream(outfile, FileMode.Create, FileAccess.Write))
                {
                    xmlSerializer.Serialize(xmlStream, iso);
                }

                Console.ReadKey();
            }
        }
開發者ID:andyvans,項目名稱:BinarySerializer,代碼行數:26,代碼來源:Program.cs

示例4: Should_throw_exception_if_byte_array_is_null

        public void Should_throw_exception_if_byte_array_is_null()
        {
            // Arrange
            var serializer = new BinarySerializer();


            // Action
            var obj = serializer.Deserialize<Customer>(null);
        }
開發者ID:sovanesyan,項目名稱:Burrow.NET,代碼行數:9,代碼來源:MethodDeserialize.cs

示例5: TestBinarySerializing

 public static void TestBinarySerializing()
 {
     var bs = new BinarySerializer<Test<string>>();
     using (var fileStream = File.Create(Path.Combine("save", "test.binx")))
     {
         bs.Serialize(fileStream, Program.GetTest());
     }
     using (var fileStream = File.OpenRead(Path.Combine("save", "test.binx")))
     {
         var test = bs.Deserialize(fileStream);
         Debug.Assert(test.SequenceEqual(Program.GetTest()));
     }
 }
開發者ID:RavingRabbit,項目名稱:Labs,代碼行數:13,代碼來源:SerializingTesting.cs

示例6: Can_serialize_object

        public void Can_serialize_object()
        {
            // Arrange
            var serializer = new BinarySerializer();


            // Action
            var str = serializer.Serialize(new Customer { FullName = "Bunny", Title = "Mr" });
            Customer obj = serializer.Deserialize<Customer>(str);

            // Asert
            Assert.AreEqual("Bunny", obj.FullName);
            Assert.AreEqual("Mr", obj.Title);
        }
開發者ID:joefeser,項目名稱:Burrow.NET,代碼行數:14,代碼來源:MethodSerialize.cs

示例7: LoadState

        private void LoadState()
        {
            try
            {
                var ser = new BinarySerializer();
                var stat = ser.Deserialize(StateFileName) as Dictionary<String, Object>;

                if (stat != null)
                {
                    foreach (var p in GetType().GetProperties())
                    {
                        if (Attribute.IsDefined(p, typeof(StateItemAttribute)))
                            p.SetValue(this, stat[p.Name], null);
                    }
                }
            }
            catch { }
        }
開發者ID:rizwan3d,項目名稱:elalang,代碼行數:18,代碼來源:StateUserControl.cs


注:本文中的BinarySerializer.Deserialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。