Exemplo n.º 1
0
        /// <summary>
        /// Lookup the mapped <see cref="IValueProcessor"/> for the supplied <see cref="Type"/>.
        /// </summary>
        /// <param name="registry">The <see cref="ITypeValueProcessorRegistry"/>.</param>
        /// <typeparam name="T">The <see cref="Type"/> for which the mapped instance should be returned.</typeparam>
        /// <param name="result">The <see cref="IValueProcessor"/></param>
        /// <returns><c>true</c> if the mapping was found; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="registry"/>' cannot be null. </exception>
        public static Boolean TryLookup <T>([NotNull] this ITypeValueProcessorRegistry registry, [CanBeNull] out IValueProcessor result)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            return(registry.TryLookup(typeof(T), out result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the mapping for the suppied <see cref="Type"/>.
        /// </summary>
        /// <param name="registry">The <see cref="ITypeValueProcessorRegistry"/>.</param>
        /// <typeparam name="T">The <see cref="Type"/>.</typeparam>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="registry"/>' cannot be null. </exception>
        public static void RemoveRegistration <T>([NotNull] this ITypeValueProcessorRegistry registry)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            registry.RemoveRegistration(typeof(T));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Maps the <see cref="IValueProcessor"/> to the <see cref="Type"/>.
        /// </summary>
        /// <param name="registry">The <see cref="ITypeValueProcessorRegistry"/>.</param>
        /// <typeparam name="T">The <see cref="Type"/>.</typeparam>
        /// <param name="valueProcessor">The <see cref="IValueProcessor"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="registry"/>' and '<paramref name="valueProcessor"/>' cannot be null. </exception>
        public static void SetRegistration <T>([NotNull] this ITypeValueProcessorRegistry registry, [NotNull] IValueProcessor valueProcessor)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (valueProcessor == null)
            {
                throw new ArgumentNullException(nameof(valueProcessor));
            }

            registry.SetRegistration(typeof(T), valueProcessor);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ValueProcessorFactory"/> class.
        /// </summary>
        /// <param name="valueProcessorRegistry">An implementation of the <see cref="ITypeValueProcessorRegistry"/> interface.</param>
        /// <param name="instanceFactory">An implementation of the <see cref="ITypeValueProcessorRegistry"/> interface.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="valueProcessorRegistry"/>' and '<paramref name="instanceFactory"/>' cannot be null. </exception>
        public ValueProcessorFactory([NotNull] ITypeValueProcessorRegistry valueProcessorRegistry, [NotNull] IInstanceFactory instanceFactory)
        {
            if (valueProcessorRegistry == null)
            {
                throw new ArgumentNullException(nameof(valueProcessorRegistry));
            }

            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            this.valueProcessorRegistry = valueProcessorRegistry;
            this.instanceFactory        = instanceFactory;
        }
 /// <summary>
 /// Initializes the <see cref="TypeValueProcessorRegistry"/> class.
 /// </summary>
 static TypeValueProcessorRegistry()
 {
     global = new TypeValueProcessorRegistry();
 }