Ejemplo n.º 1
0
        /// <summary>
        /// Gets the instances from any given assembly path with specific filter
        /// </summary>
        /// <typeparam name="T">Generic - any interface</typeparam>
        /// <param name="assemblyPath">assemblies folder location</param>
        /// <param name="filter">file filter</param>
        /// <returns>List of Ts</returns>
        public static IList <T> GetInstancesFromAssemblyPath <T>(string assemblyPath, string filter)
        {
            IList <T> instances = new List <T>();

            foreach (string filename in Directory.GetFiles(assemblyPath, filter))
            {
                IList <object> registeredInstances = AssemblyResolver.Resolve(filename);
                IList <T>      instancesT          = Register <T>(registeredInstances);
                foreach (T obj in instancesT)
                {
                    if (obj != null && instances.FirstOrDefault(IA => string.Compare(IA.GetType().FullName,
                                                                                     obj.GetType().FullName, StringComparison.InvariantCultureIgnoreCase) == 0) == null)
                    {
                        instances.Add((T)obj);
                    }
                }
            }
            return(instances);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the instances from any given assembly path with specific filter.
        /// </summary>
        /// <typeparam name="T">Generic - any interface.</typeparam>
        /// <param name="assemblyPath">Assemblies folder location.</param>
        /// <param name="filter">File filter.</param>
        /// <returns>List of Ts.</returns>
        public static IList <T> GetInstancesFromAssemblyPath <T>(string assemblyPath, string filter)
            where T : class
        {
            List <T> instances = new List <T>();

            if (!string.IsNullOrEmpty(assemblyPath))
            {
                // Next, search the add-ins directly for the proper attributes
                foreach (string filename in Directory.GetFiles(assemblyPath, filter))
                {
                    IList <object> registeredInstances = AssemblyResolver.Resolve(filename);
                    IList <T>      instancesT          = Register <T>(registeredInstances);
                    foreach (T obj in instancesT.Where(
                                 obj => obj != null &&
                                 instances.All(at => string.Compare(at.GetType().FullName, obj.GetType().FullName, StringComparison.OrdinalIgnoreCase) != 0)))
                    {
                        instances.Add(obj);
                    }
                }
            }

            return(instances);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the instances from the executing assembly.
        /// </summary>
        /// <typeparam name="T">Generic - any interface.</typeparam>
        /// <returns>List of Ts.</returns>
        public static IList <T> GetInstancesFromExecutingAssembly <T>()
        {
            IList <object> registeredInstances = AssemblyResolver.Resolve();

            return(Register <T>(registeredInstances));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the instances from any given assembly file.
        /// </summary>
        /// <typeparam name="T">Generic - any interface.</typeparam>
        /// <param name="assemblyName">Assembly file.</param>
        /// <returns>List of Ts.</returns>
        public static IList <T> GetInstancesFromAssembly <T>(string assemblyName)
        {
            IList <object> registeredInstances = AssemblyResolver.Resolve(assemblyName);

            return(Register <T>(registeredInstances));
        }