本文整理汇总了C#中Formatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# Formatter.Deserialize方法的具体用法?C# Formatter.Deserialize怎么用?C# Formatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formatter
的用法示例。
在下文中一共展示了Formatter.Deserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeGeneric_BinaryFormatted_Deserialized
public void DeserializeGeneric_BinaryFormatted_Deserialized()
{
// ReSharper disable once AssignNullToNotNullAttribute
var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName, new byte[0]);
var subject = new Formatter(
_binarySerializerMock.Object,
_unityJsonSerializerMock.Object,
_formatSelectorMock.Object);
var testData = new TestData();
_binarySerializerMock.Setup(mock => mock.Deserialize(It.IsAny<byte[]>()))
.Returns(testData);
var result = subject.Deserialize<TestData>(serializationInfo);
Assert.AreEqual(testData, result);
}
示例2: Deserialize_NullFormatted_Null
public void Deserialize_NullFormatted_Null()
{
// ReSharper disable once AssignNullToNotNullAttribute
var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName);
var subject = new Formatter(
_binarySerializerMock.Object,
_unityJsonSerializerMock.Object,
_formatSelectorMock.Object);
var result = subject.Deserialize(serializationInfo);
Assert.IsNull(result);
}
示例3: Deserialize_TypeNotResolved_Throws
public void Deserialize_TypeNotResolved_Throws()
{
var serializationInfo = new SerializedValue("12345", "12345");
var subject = new Formatter(
_binarySerializerMock.Object,
_unityJsonSerializerMock.Object,
_formatSelectorMock.Object);
var testData = new TestData();
_unityJsonSerializerMock.Setup(mock => mock.Deserialize(It.IsAny<Type>(), It.IsAny<string>()))
.Returns(testData);
Assert.Throws<InvalidOperationException>(() => subject.Deserialize(serializationInfo));
}
示例4: DeserializeGeneric_TypeNotAssignalbe_Throws
public void DeserializeGeneric_TypeNotAssignalbe_Throws()
{
// ReSharper disable once AssignNullToNotNullAttribute
var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName, "12345");
var subject = new Formatter(
_binarySerializerMock.Object,
_unityJsonSerializerMock.Object,
_formatSelectorMock.Object);
Assert.Throws<InvalidOperationException>(() => subject.Deserialize<int>(serializationInfo));
}