本文整理汇总了C#中Serializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.Deserialize方法的具体用法?C# Serializer.Deserialize怎么用?C# Serializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static string Run(string out_dir)
{
var sb = new StringBuilder();
// Time creation of serializer
var sw = new Stopwatch();
var serializer = new Serializer();
sb.AppendLine("Serializer init took " + sw.Elapsed);
var data = SubClass.Sample();
// Time serializing prefs
string out_file = Path.Combine(out_dir, "data.bin");
sw.Reset();
using (var stream = File.Create(out_file))
{
serializer.Serialize(stream, data);
}
sb.AppendLine("Serialization took " + sw.Elapsed);
// Time de-serializing prefs
sw.Reset();
using (var stream = File.OpenRead(out_file))
{
data = (SubClass)serializer.Deserialize(stream, null, typeof(SubClass));
}
sb.AppendLine("De-serialization took " + sw.Elapsed);
sb.AppendLine("Date_Saved: " + data.Date_Saved);
sb.AppendLine("Field1: " + data.Field1);
sb.AppendLine("Field2: " + data.Field2);
return sb.ToString();
}
示例2: Expect_that_a_serialized_object_can_be_deserialized_accurately
public void Expect_that_a_serialized_object_can_be_deserialized_accurately()
{
var objIn = new TestState {
A = decimal.MaxValue,
B = "Hello World!",
C = DateTime.MaxValue,
D = long.MaxValue,
E = new byte[] { 1, 2, 3 },
F = true
};
var ms = new MemoryStream(128);
var serializer = new Serializer();
serializer.Serialize(ms, objIn);
ms.Position = 0;
var objOut = serializer.Deserialize<TestState>(ms);
Assert.That(objOut.A == objIn.A);
Assert.That(objOut.B == objIn.B);
Assert.That(objOut.C == objIn.C);
Assert.That(objOut.D == objIn.D);
Assert.That(objOut.E.SequenceEqual(objIn.E));
Assert.That(objOut.F == objIn.F);
}
示例3: PerformDeserializationTest
public override void PerformDeserializationTest(Serializer serializer, Stream target)
{
var got = serializer.Deserialize(target);
var originalRoot = m_List ? (object)m_Data : m_Data[0];
serializer.AssertPayloadEquality(this, originalRoot, got);
}
示例4: LoadYamlFile
private static Dictionary<object, object> LoadYamlFile(string filePath)
{
using (var stream = File.OpenRead(filePath))
{
var formatter = new Serializer();
return formatter.Deserialize<Dictionary<object, object>>(stream);
};
}
示例5: CanSerializeMessageWithByte
public void CanSerializeMessageWithByte()
{
var stream = new MemoryStream();
var msg = new ByteMessage(DateTime.UtcNow,1,2);
var serializer = new Serializer(new SerializerOptions(versionTolerance: true, preserveObjectReferences: true));
serializer.Serialize(msg, stream);
stream.Position = 0;
var res = serializer.Deserialize(stream);
}
示例6: NotSpecifyingObjectFactoryUsesDefault
public void NotSpecifyingObjectFactoryUsesDefault()
{
var settings = new SerializerSettings();
settings.RegisterTagMapping("!foo", typeof(FooBase));
var serializer = new Serializer(settings);
var result = serializer.Deserialize(new StringReader("!foo {}"));
Assert.IsInstanceOf<FooBase>(result);
}
示例7: GUIController
public GUIController(GUIView view)
{
Serializer = new Serializer(this);
Model = Serializer.Deserialize();
if(Model == null) Model = new GUIModel();
View = view;
View.UpdateView(Model);
}
示例8: CanSerialieCustomType_bug
public void CanSerialieCustomType_bug()
{
var stream = new MemoryStream();
var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true,versionTolerance:true));
var root = new Recover(SnapshotSelectionCriteria.Latest);
serializer.Serialize(root, stream);
stream.Position = 0;
var actual = serializer.Deserialize<Recover>(stream);
}
示例9: Run
public void Run(string[] args)
{
// Setup the input
var input = new StringReader(_document);
var deserializer = new Serializer();
var order = (Order)deserializer.Deserialize(input, typeof(Order));
Console.WriteLine("Receipt: {0}", order.Receipt);
Console.WriteLine("Customer: {0} {1}", order.Customer.Given, order.Customer.Family);
}
示例10: Test_Serializer
public void Test_Serializer()
{
var serializer = new Serializer();
var fixture = new Fixture();
var data = fixture.Create<ApplicationEditData>();
var bytes = serializer.Serialize(data);
var actual = serializer.Deserialize<ApplicationEditData>(bytes);
actual.ShouldBeEquivalentTo(data);
}
示例11: Deserialization_PerformanceTest
public void Deserialization_PerformanceTest()
{
const int numberOfRecords = 50000;
var serializer = new Serializer(FullSchema());
using (var stream = BuildLargeXml(numberOfRecords)) // Roughly 25MB
{
long length = stream.Length;
Benchmark("XMapper", length, () => { stream.Seek(0, SeekOrigin.Begin); serializer.Deserialize<Document>(stream); });
}
}
示例12: Loader
private SceneRenderer Loader(string name)
{
// Scene loading
SceneContainer scene;
var ser = new Serializer();
string filename = "Assets/" + name + ".fus";
using (var file = File.OpenRead(@filename))
{
scene = ser.Deserialize(file, null, typeof(SceneContainer)) as SceneContainer;
}
_sr = new SceneRenderer(scene, "Assets");
return _sr;
}
示例13: Search
public CalendarCollection Search(CalDav.CalendarQuery query) {
var result = Common.Request(Url, "REPORT", (XElement)query, Credentials, new Dictionary<string, object> {
{ "Depth", 1 }
});
var xdoc = XDocument.Parse(result.Item2);
var data = xdoc.Descendants(CalDav.Common.xCalDav.GetName("calendar-data"));
var serializer = new Serializer();
return new CalendarCollection(data.SelectMany(x => {
using (var rdr = new System.IO.StringReader(x.Value)) {
return serializer.Deserialize<CalendarCollection>(rdr);
}
}));
}
示例14: GetObjectByUID
public ICalendarObject GetObjectByUID(ICalendarInfo calendar, string uid) {
var filename = System.IO.Path.Combine(_Directory, calendar.ID, uid + ".ics");
if (!System.IO.File.Exists(filename)) return null;
var serializer = new Serializer();
using (var file = System.IO.File.OpenText(filename)) {
var ical = (serializer.Deserialize<CalendarCollection>(file))[0];
return ical.Events.OfType<ICalendarObject>()
.Union(ical.ToDos)
.Union(ical.FreeBusy)
.Union(ical.JournalEntries)
.FirstOrDefault();
}
}
示例15: WcfChannelCanUse
private static bool WcfChannelCanUse()
{
WcfChannel channel = CreateWcfChannel();
NetworkInvokePackage pk = new NetworkInvokePackage(NetworkInvokeType.Ping, Guid.NewGuid().ToString());
try {
Serializer serializer = new Serializer();
byte[] data = channel.Invoke(serializer.Serialize<NetworkInvokePackage>(pk));
return serializer.Deserialize<bool>(data);
}
catch {
return false;
}
}