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


C# Serializer.DeserializeFromStream方法代码示例

本文整理汇总了C#中Serializer.DeserializeFromStream方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.DeserializeFromStream方法的具体用法?C# Serializer.DeserializeFromStream怎么用?C# Serializer.DeserializeFromStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serializer的用法示例。


在下文中一共展示了Serializer.DeserializeFromStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            var user = new User();
            user.Id = 1;
            user.Email = "[email protected]";
            user.Image = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            user.CreatedAt = DateTime.Now;
            user.Tags = new List<string>();
            user.Tags.Add("soccer");

            var serializer = new Serializer();

            var content = new PushStreamContent((stream, httpContent, transportContext) =>
            {
                serializer.SerializeToStream(user, stream);
                stream.Close();
            });

            var client = new HttpClient();

            var response = client.PostAsync("http://localhost:19012/api/values/myItem?replace=false", content).ConfigureAwait(false).GetAwaiter().GetResult();
            response.EnsureSuccessStatusCode();

            var nextResponse = client.GetAsync("http://localhost:19012/api/values/myItem").ConfigureAwait(false).GetAwaiter().GetResult();

            var responseStream = nextResponse.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            var otherUser = serializer.DeserializeFromStream<User>(responseStream);
        }
开发者ID:BredStik,项目名称:ProtobufCache,代码行数:29,代码来源:Program.cs

示例2: Serializes_and_deserializes_without_attributes

        public void Serializes_and_deserializes_without_attributes()
        {
            var serializer = new Serializer();
            var user = new User();
            user.Id = 1;
            user.Email = "[email protected]";
            user.Image = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            user.CreatedAt = DateTime.Now;
            user.Tags = new List<string>();
            user.Tags.Add("soccer");

            var serialized = serializer.SerializeToStream(user);
            serialized.Position = 0;
            var deserialized = serializer.DeserializeFromStream<User>(serialized);
            Assert.AreEqual(user.Id, deserialized.Id);
            Assert.AreEqual(user.Email, deserialized.Email);
            Assert.AreEqual(user.Image, deserialized.Image);
            Assert.AreEqual(user.CreatedAt, deserialized.CreatedAt);
            Assert.AreEqual(user.Tags, deserialized.Tags);
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:20,代码来源:ProtocolBuffersSerializerTests.cs


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