コード例 #1
0
        /// <summary>
        /// Add a converter for the given Source to Destination conversion.
        /// </summary>
        /// <typeparam name="TSource">Source type.</typeparam>
        /// <typeparam name="TDestination">Destination type.</typeparam>
        /// <typeparam name="TAttribute">Attribute on the binding. </typeparam>
        /// <param name="converterManager">Instance of Converter Manager.</param>
        /// <param name="converterInstance">Instance of an object with convert methods on it.</param>
        public static void AddConverter <TSource, TDestination, TAttribute>(
            this ConverterManager converterManager,
            object converterInstance)
            where TAttribute : Attribute
        {
            var patternMatcher = PatternMatcher.NewObj(converterInstance);

            converterManager.AddConverterBuilder <TSource, TDestination, TAttribute>(patternMatcher);
        }
コード例 #2
0
        /// <summary>
        /// Add a converter for the given Source to Destination conversion.
        /// The typeConverter type is instantiated with the type arguments and constructorArgs is passed.
        /// </summary>
        /// <typeparam name="TSource">Source type.</typeparam>
        /// <typeparam name="TDestination">Destination type.</typeparam>
        /// <typeparam name="TAttribute">Attribute on the binding. </typeparam>
        /// <param name="converterManager">Instance of Converter Manager.</param>
        /// <param name="typeConverter">A type with conversion methods. This can be generic and will get instantiated with the
        /// appropriate type parameters. </param>
        /// <param name="constructorArgs">Constructor Arguments to pass to the constructor when instantiated. This can pass configuration and state.</param>
        public static void AddConverter <TSource, TDestination, TAttribute>(
            this ConverterManager converterManager,
            Type typeConverter,
            params object[] constructorArgs)
            where TAttribute : Attribute
        {
            var patternMatcher = PatternMatcher.New(typeConverter, constructorArgs);

            converterManager.AddConverterBuilder <TSource, TDestination, TAttribute>(patternMatcher);
        }