本文整理汇总了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);
}
}
示例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 { }
}
示例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();
}
}
示例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);
}
示例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()));
}
}
示例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);
}
示例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 { }
}