// Constructors

        public EnumAdvancedConverter(IAdvancedConverterProvider provider)
            : base(provider)
        {
            Type toType   = typeof(TTo);
            Type fromType = typeof(TFrom);

            if (!toType.IsEnum && !fromType.IsEnum)
            {
                throw new InvalidOperationException();
            }
            if (!typeof(TFrom).IsEnum)
            {
                inputValueTypeAdvancedConverter = provider.GetConverter <TFrom, TIntermediate>();
            }
            if (!typeof(TTo).IsEnum)
            {
                outputValueTypeAdvancedConverter = provider.GetConverter <TIntermediate, TTo>();
            }
        }
        // Constructors

        public EnumAdvancedConverter(IAdvancedConverterProvider provider)
            : base(provider)
        {
            // Checking types
            Type toType   = typeof(TTo);
            Type fromType = typeof(TFrom);

            if (!toType.IsEnum && !fromType.IsEnum)
            {
                throw new InvalidOperationException();
            }
            intermediateConverter2 = provider.GetConverter <TUnderlyingFrom, TUnderlyingTo>();
        }
Exemplo n.º 3
0
        public void ConverterTest()
        {
            IAdvancedConverterProvider      provider = AdvancedConverterProvider.Default;
            AdvancedConverter <int, string> intStringAdvancedConverter = provider.GetConverter <int, string>();

            Assert.AreEqual("Int32AdvancedConverter", intStringAdvancedConverter.Implementation.GetType().Name);
            Assert.IsTrue(!(intStringAdvancedConverter.IsRough));
            Assert.IsFalse(intStringAdvancedConverter.IsRough);
            int    intValue         = 1234;
            string intToStringValue = intStringAdvancedConverter.Convert(intValue);

            TestLog.Info("IntToString: {0} {1}", intValue, intToStringValue);
            Assert.AreEqual(intValue.ToString(), intToStringValue);
        }
        // Constructors

        /// <summary>
        /// Creates new instance of <see cref="WrappingAdvancedConverter{TFrom,TFromBase,TTo,TToBase}"/>.
        /// </summary>
        /// <param name="provider">Converter provider this converter is bound to.</param>
        public WrappingAdvancedConverter(IAdvancedConverterProvider provider)
            : base(provider)
        {
            BaseConverter = provider.GetConverter <TFromBase, TToBase>();
        }