领胜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
45
46
47
48
49
50
51
52
53
using Bro.Common.Base;
using Bro.Common.Helper;
using Bro.Common.Interface;
using System;
using System.Collections.Generic;
using System.Reflection;
using static Bro.Common.Helper.EnumHelper;
 
namespace Bro.Common.Factory
{
    public static class ConfigFactory
    {
        public static IOperationConfig GetOperationConfig(string typeName)
        {
            Type configType = FactoryHelper.GetTypeByAtrributeTypeName(typeName, DeviceAttributeType.OperationConfig);
 
            if (configType == null)
            {
                return new OperationConfigBase();
            }
 
            return Activator.CreateInstance(configType) as IOperationConfig;
        }
 
        public static IInitialConfig GetInitialConfig(string typeName)
        {
            Type configType = FactoryHelper.GetTypeByAtrributeTypeName(typeName, DeviceAttributeType.InitialConfig);
 
            if (configType == null)
            {
                return null;
            }
 
            return Activator.CreateInstance(configType) as IInitialConfig;
        }
 
        public static Dictionary<string, Type> GetAllOpConfigTypes()
        {
            Dictionary<string, Type> opConfigTypeDict = new Dictionary<string, Type>();
            FactoryHelper.TYPES.ForEach(t =>
            {
                var attr = t.GetCustomAttribute<DeviceAttribute>();
 
                if (attr != null && attr.AttrType == DeviceAttributeType.OperationConfig)
                {
                    opConfigTypeDict[attr.TypeCode] = t;
                }
            });
 
            return opConfigTypeDict;
        }
    }
}