public void CorrectlyMapsTypesToConverters(object obj, Type expectedType)
        {
            var fromGetType = ConvertersSelector.SelectConverter(obj);
            var fromType    = ConvertersSelector.ForSerializedType(fromGetType.Type);

            fromGetType.Should().Be(fromType);
            fromGetType.Should().BeOfType(expectedType);
        }
        public void CorrectlyMapsTypesToConverters(object obj, Type expectedType)
        {
            var fromType           = ConvertersSelector.SelectConverter(obj);
            var fromSerializedType = ConvertersSelector.ForSerializedType(fromType.Type);

            Assert.Equal(fromType, fromSerializedType);
            Assert.Equal(fromType.GetType(), expectedType);
        }
Пример #3
0
        protected override void SerializeInternal(object obj, SerializationStream stream)
        {
            var fields = obj.GetType().GetFieldsAccessibleForSerializer();

            foreach (var field in fields)
            {
                object prop      = field.GetValue(obj);
                var    converter = ConvertersSelector.SelectConverter(prop);
                converter.Serialize(prop, stream);
            }
        }
        protected override void WriteObjectToStream(object obj, Stream stream)
        {
            Type t = obj.GetType();

            ICollection <PropertyInfo> properties = t.GetTypeInfo().GetAllProperties().ToArray();

            foreach (PropertyInfo property in properties)
            {
                if (!property.CanWrite || property.GetMethod.IsStatic)
                {
                    continue;
                }

                object prop      = property.GetValue(obj);
                var    converter = ConvertersSelector.SelectConverter(prop);
                converter.Serialize(prop, stream);
            }
        }
        public void ReturnsNullConverter_WhenObjIsNull()
        {
            var converter = ConvertersSelector.SelectConverter(null);

            converter.Should().BeOfType <NullConverter>();
        }
        public void ReturnsNullConverter_WhenObjIsNull()
        {
            var converter = ConvertersSelector.SelectConverter(null);

            Assert.True(converter is NullConverter);
        }