Ejemplo n.º 1
0
        /// <inheritdoc/>
        public virtual void WriteField <T>(T field)
        {
            var type      = field == null ? typeof(string) : field.GetType();
            var converter = typeConverterCache.GetConverter(type);

            WriteField(field, converter);
        }
        public void GetConverter_ConverterRegisteredForEnum_ReturnCustomConverterForAllEnums()
        {
            var typeConverterFactory = new TypeConverterCache();

            typeConverterFactory.AddConverter <Enum>(new TestKnownConverter());
            var fooConverter = typeConverterFactory.GetConverter(typeof(FooEnum));
            var barConverter = typeConverterFactory.GetConverter(typeof(BarEnum));

            Assert.IsType <TestKnownConverter>(fooConverter);
            Assert.IsType <TestKnownConverter>(barConverter);
        }
Ejemplo n.º 3
0
        public void GetConverterForKnownTypeTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter <TestKnownClass>();

            Assert.IsInstanceOfType(converter, typeof(DefaultTypeConverter));

            typeConverterFactory.AddConverter <TestKnownClass>(new TestKnownConverter());
            converter = typeConverterFactory.GetConverter <TestKnownClass>();

            Assert.IsInstanceOfType(converter, typeof(TestKnownConverter));
        }
        public void GetConverterForKnownTypeTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter <TestKnownClass>();

            Assert.IsType <DefaultTypeConverter>(converter);

            typeConverterFactory.AddConverter <TestKnownClass>(new TestKnownConverter());
            converter = typeConverterFactory.GetConverter <TestKnownClass>();

            Assert.IsType <TestKnownConverter>(converter);
        }
        public void GetConverterForSByteTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(sbyte));

            Assert.IsType <SByteConverter>(converter);
        }
        public void GetConverterForNullableTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(int?));

            Assert.IsType <NullableConverter>(converter);
        }
        public void GetConverterForUnknownTypeTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(TestUnknownClass));

            Assert.IsType <DefaultTypeConverter>(converter);
        }
Ejemplo n.º 8
0
        public void TypeConverterCacheTest()
        {
            var cache     = new TypeConverterCache();
            var converter = cache.GetConverter <Uri>();

            Assert.IsType <UriConverter>(converter);
        }
        public void GetConverterForDoubleTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(double));

            Assert.IsType <DoubleConverter>(converter);
        }
        public void GetConverterForCharTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(char));

            Assert.IsType <CharConverter>(converter);
        }
        public void GetConverterForEnumTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(FooEnum));

            Assert.IsType <EnumConverter>(converter);
        }
Ejemplo n.º 12
0
        public void GetConverterForEnumTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(FooEnum));

            Assert.IsInstanceOfType(converter, typeof(EnumConverter));
        }
        public void GetConverterForStringTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(string));

            Assert.IsType <StringConverter>(converter);
        }
Ejemplo n.º 14
0
        public void GetConverterForUInt64Test()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(ulong));

            Assert.IsInstanceOfType(converter, typeof(UInt64Converter));
        }
Ejemplo n.º 15
0
        public void GetConverterForStringTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(string));

            Assert.IsInstanceOfType(converter, typeof(StringConverter));
        }
Ejemplo n.º 16
0
        public void GetConverterForInt32Test()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(int));

            Assert.IsInstanceOfType(converter, typeof(Int32Converter));
        }
Ejemplo n.º 17
0
        public void GetConverterForFloatTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(float));

            Assert.IsInstanceOfType(converter, typeof(SingleConverter));
        }
Ejemplo n.º 18
0
        public void TypeConverterCacheTest()
        {
            var cache     = new TypeConverterCache();
            var converter = cache.GetConverter <Uri>();

            Assert.IsInstanceOfType(converter, typeof(UriConverter));
        }
        public void GetConverterForUInt64Test()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(ulong));

            Assert.IsType <UInt64Converter>(converter);
        }
Ejemplo n.º 20
0
        public void GetConverterForByteArrayTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(byte[]));

            Assert.IsInstanceOfType(converter, typeof(ByteArrayConverter));
        }
Ejemplo n.º 21
0
        public void GetConverterForCharTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(char));

            Assert.IsInstanceOfType(converter, typeof(CharConverter));
        }
Ejemplo n.º 22
0
        public void GetConverterForDoubleTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(double));

            Assert.IsInstanceOfType(converter, typeof(DoubleConverter));
        }
        public void GetConverterForByteArrayTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(byte[]));

            Assert.IsType <ByteArrayConverter>(converter);
        }
        public void GetConverterForGuidTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(Guid));

            Assert.IsType <GuidConverter>(converter);
        }
        public void GetConverterForDecimalTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(decimal));

            Assert.IsType <DecimalConverter>(converter);
        }
        public void GetConverterForInt32Test()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(int));

            Assert.IsType <Int32Converter>(converter);
        }
        public void GetConverterForFloatTest()
        {
            var typeConverterFactory = new TypeConverterCache();
            var converter            = typeConverterFactory.GetConverter(typeof(float));

            Assert.IsType <SingleConverter>(converter);
        }
Ejemplo n.º 28
0
 public NullConverter(Type type, TypeConverterCache typeConverterFactory)
 {
     _underlyingTypeConverter = typeConverterFactory.GetConverter(type);
 }