コード例 #1
0
ファイル: VisitorFactory.cs プロジェクト: QuickOrBeDead/abioc
        /// <summary>
        /// Creates the visitors that are <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> to the specified type.
        /// </summary>
        /// <typeparam name="TRegistration">The type of visitor.</typeparam>
        /// <param name="container">The <see cref="CompositionContainer"/>.</param>
        /// <param name="manager">The <see cref="VisitorManager"/>.</param>
        /// <returns>
        /// The visitors that are <see cref="TypeInfo.IsAssignableFrom(TypeInfo)"/> to the specified type.
        /// </returns>
        public IEnumerable <IRegistrationVisitor <TRegistration> > CreateVisitors <TRegistration>(
            CompositionContainer container,
            VisitorManager manager)
            where TRegistration : class, IRegistration
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            Type visitorType = typeof(IRegistrationVisitor <TRegistration>);

            IReadOnlyList <object> nonTypedFactories =
                VisitorFactoryCache.GetOrAdd(visitorType, t => CreateVisitorFactories <TRegistration>());

            IEnumerable <Func <CompositionContainer, VisitorManager, IRegistrationVisitor <TRegistration> > > factories =
                nonTypedFactories
                .Cast <Func <CompositionContainer, VisitorManager, IRegistrationVisitor <TRegistration> > >();

            return(factories.Select(f => f(container, manager)));
        }
コード例 #2
0
ファイル: VisitorManager.cs プロジェクト: QuickOrBeDead/abioc
        private static void VisitRegistration <TRegistration>(VisitorManager manager, IRegistration registration)
            where TRegistration : class, IRegistration
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            Type visitorType = typeof(IRegistrationVisitor <TRegistration>);

            if (!manager._visitors.TryGetValue(visitorType, out IRegistrationVisitor[] visitors))
コード例 #3
0
        private static void ProcessRegistrations(
            CompositionContainer container,
            IEnumerable <Type> externalVisitorTypes = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var visitorManager = new VisitorManager(container, externalVisitorTypes);

            IEnumerable <IRegistration> registrations = container.Registrations.Values.SelectMany(r => r);

            foreach (IRegistration registration in registrations)
            {
                visitorManager.Visit(registration);
            }
        }