当前位置: 首页>>代码示例>>C#>>正文


C# Serializer.Deserialize方法代码示例

本文整理汇总了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();
        }
开发者ID:t9mike,项目名称:ProtoBuf1,代码行数:34,代码来源:TestSerialization.cs

示例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);
        }
开发者ID:nbevans,项目名称:EventStreams,代码行数:25,代码来源:SerializerTests.cs

示例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);
        }
开发者ID:huoxudong125,项目名称:serbench,代码行数:7,代码来源:TypicalPerson.cs

示例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);
     };
 }
开发者ID:Belorus,项目名称:DynamicConfig,代码行数:8,代码来源:Program.cs

示例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);
 }
开发者ID:akkadotnet,项目名称:Wire,代码行数:9,代码来源:Bugs.cs

示例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);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:9,代码来源:ObjectFactoryTests.cs

示例7: GUIController

        public GUIController(GUIView view)
        {
            Serializer = new Serializer(this);
            Model = Serializer.Deserialize();
            if(Model == null) Model = new GUIModel();

            View = view;
            View.UpdateView(Model);
        }
开发者ID:Needix,项目名称:Network_Chat,代码行数:9,代码来源:GUIController.cs

示例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);
        }
开发者ID:Horusiath,项目名称:Wire,代码行数:10,代码来源:Bugs.cs

示例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);
		}
开发者ID:modulexcite,项目名称:SharpYaml,代码行数:11,代码来源:DeserializeObjectGraph.cs

示例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);
		}
开发者ID:UHgEHEP,项目名称:test,代码行数:12,代码来源:SerializerTests.cs

示例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); });
            }
        }
开发者ID:bitserf,项目名称:xmapper,代码行数:12,代码来源:PerformanceTest.cs

示例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;
 }
开发者ID:GameProduction,项目名称:ScharfschiessenGame,代码行数:13,代码来源:SceneLoader.cs

示例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);
				}
			}));
		}
开发者ID:hiblen,项目名称:CalDav,代码行数:13,代码来源:Calendar.cs

示例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();
			}
		}
开发者ID:hiblen,项目名称:CalDav,代码行数:13,代码来源:CalendarRepository.cs

示例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;
     }
 }
开发者ID:wuyingyou,项目名称:uniframework,代码行数:13,代码来源:CommunicatorFactory.cs


注:本文中的Serializer.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。