using Bro.Common.Helper;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
|
namespace Bro.Common.Factory
|
{
|
public static class ElementFactory
|
{
|
public static Dictionary<ElementAttribute, Type> GetAllElementsInfo()
|
{
|
Dictionary<ElementAttribute, Type> dict = new Dictionary<ElementAttribute, Type>();
|
List<string> eleDlls = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).GetFiles("Bro.Element.*.dll").Select(u => u.FullName).ToList();
|
|
eleDlls.ForEach(dll =>
|
{
|
Assembly assm = Assembly.LoadFile(dll);
|
assm.GetTypes().ToList().ForEach(u =>
|
{
|
var attr = u.GetCustomAttribute<ElementAttribute>();
|
|
if (attr != null)
|
{
|
dict[attr] = u;
|
}
|
});
|
});
|
|
Assembly.GetExecutingAssembly().GetTypes().ToList().ForEach(u =>
|
{
|
var attr = u.GetCustomAttribute<ElementAttribute>();
|
|
if (attr != null)
|
{
|
dict[attr] = u;
|
}
|
});
|
|
return dict;
|
}
|
}
|
}
|