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