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


C# Formatter.Serialize方法代码示例

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


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

示例1: Serialize_TypeWithoutNull_Throws

        public void Serialize_TypeWithoutNull_Throws()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            var type = new TypeWithoutAssemblyQualifiedName();

            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws<ArgumentException>(() => subject.Serialize(type, new object()));
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:12,代码来源:FormatterTest.cs

示例2: Serialize_TypeNull_Throws

        public void Serialize_TypeNull_Throws()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws<ArgumentNullException>(() => subject.Serialize(null, new object()));
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:10,代码来源:FormatterTest.cs

示例3: Serialize_SerializationFormatNull_NullFormatted

        public void Serialize_SerializationFormatNull_NullFormatted()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            _formatSelectorMock.Setup(mock => mock.GetFormat(It.IsAny<Type>(), It.IsAny<object>()))
                .Returns(SerializationFormat.Null);

            var result = subject.Serialize(typeof(TestData), null);

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(TestData).AssemblyQualifiedName, result.AssemblyQualifiedName);
            Assert.AreEqual(SerializationFormat.Null, result.Format);
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:16,代码来源:FormatterTest.cs

示例4: Serialize_NotSupportedFormat_Throws

        public void Serialize_NotSupportedFormat_Throws()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            _formatSelectorMock.Setup(mock => mock.GetFormat(It.IsAny<Type>(), It.IsAny<object>()))
                .Returns((SerializationFormat)int.MaxValue);

            Assert.Throws<NotSupportedException>(() => subject.Serialize(typeof(TestData), new TestData()));
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:12,代码来源:FormatterTest.cs

示例5: SerializeGeneric_SerializationFormatJson_JsonFormatted

        public void SerializeGeneric_SerializationFormatJson_JsonFormatted()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);
            const string serializedData = "12345";

            _formatSelectorMock.Setup(mock => mock.GetFormat(It.IsAny<Type>(), It.IsAny<object>()))
                .Returns(SerializationFormat.UnityJson);
            _unityJsonSerializerMock.Setup(mock => mock.Serialize(It.IsAny<object>()))
                .Returns(serializedData);

            var result = subject.Serialize<TestData>(null);

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(TestData).AssemblyQualifiedName, result.AssemblyQualifiedName);
            Assert.AreEqual(SerializationFormat.UnityJson, result.Format);
            Assert.AreEqual(serializedData, result.JsonData);
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:20,代码来源:FormatterTest.cs

示例6: SerializeGeneric_SerializationFormatBinary_BinaryFormatted

        public void SerializeGeneric_SerializationFormatBinary_BinaryFormatted()
        {
            var subject = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);
            var serializedData = new byte[] { 1, 2, 3, 42, 2 };

            _formatSelectorMock.Setup(mock => mock.GetFormat(It.IsAny<Type>(), It.IsAny<object>()))
                .Returns(SerializationFormat.BinaryFormatter);
            _binarySerializerMock.Setup(mock => mock.Serialize(It.IsAny<object>()))
                .Returns(serializedData);

            var result = subject.Serialize<TestData>(null);

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(TestData).AssemblyQualifiedName, result.AssemblyQualifiedName);
            Assert.AreEqual(SerializationFormat.BinaryFormatter, result.Format);
            Assert.AreEqual(serializedData, result.BinaryData);
        }
开发者ID:JackTheRipper42,项目名称:Binding,代码行数:20,代码来源:FormatterTest.cs


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