コード例 #1
0
        /// <summary>
        /// Loads all implementations of type from the currently known types
        /// KnownTypes: Types in default framework folders and deeper.
        /// </summary>
        public virtual void LoadComponents <T>(Predicate <Type> condition) where T : class
        {
            if (_knownTypes == null)
            {
                _knownTypes = ReflectionTool.GetAssemblies()
                              .Where(a => a.GetCustomAttribute <ComponentLoaderIgnoreAttribute>() == null)
                              .SelectMany(a => a.GetTypes())
                              .Where(t => t.GetCustomAttribute <RegistrationAttribute>(true) != null).ToArray();
            }

            foreach (var type in _knownTypes.Where(type => typeof(T).IsAssignableFrom(type)))
            {
                if (Registrator.ShallInstall(type) && (condition?.Invoke(type) ?? true))
                {
                    Registrator.Register(type);
                }
            }
        }