领胜LDS 键盘AOI检测项目
wells.liu
2020-07-07 5918194fccdb2a2303e713b8d2f3335243b9e2ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
        }
    }
}