using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace NCC.Common.Finder { /// /// 查找器基类 /// public abstract class FinderBase : IFinderBase { public FinderBase() { var path = AppDomain.CurrentDomain.BaseDirectory; var files = Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly) .ToArray(); var assemblies = files.Select(Assembly.LoadFrom).Distinct().ToArray(); var types = assemblies.SelectMany(x => x.GetTypes()).ToList(); LoadTypes = types; } /// /// 获取所有类型 /// public List LoadTypes { get; private set; } /// /// 所有程序集类型 /// /// public Type[] FinderAll() { return Find(); } /// /// 按类型获取 /// /// /// public Type FinderType(Type type) { var typeService = Find().FirstOrDefault(x => x == type); return typeService; } public abstract Type[] Find(); } }