|
6 | 6 | using System.Linq; |
7 | 7 | using System.Reflection; |
8 | 8 | using System.Text; |
| 9 | +using System.Xml.Linq; |
9 | 10 |
|
10 | 11 | namespace QpTestClient |
11 | 12 | { |
12 | 13 | public class QpClientTypeManager |
13 | 14 | { |
14 | 15 | public static QpClientTypeManager Instance { get; } = new QpClientTypeManager(); |
15 | 16 | private Dictionary<string, QpClientTypeInfo> dict = null; |
16 | | - public void Init() |
| 17 | + |
| 18 | + private void register<TClient>() |
17 | 19 | { |
18 | | - dict = new Dictionary<string, QpClientTypeInfo>(); |
19 | | - foreach (var dllFile in Directory.GetFiles(".", $"{nameof(Quick)}.{nameof(Quick.Protocol)}.*.dll")) |
20 | | - { |
21 | | - var assembly = Assembly.Load(Path.GetFileNameWithoutExtension(dllFile)); |
22 | | - foreach (var type in assembly.GetTypes()) |
23 | | - { |
24 | | - if (!type.IsClass || !typeof(QpClient).IsAssignableFrom(type)) |
25 | | - continue; |
| 20 | + register(typeof(TClient)); |
| 21 | + } |
26 | 22 |
|
27 | | - var typeConstructor = type.GetConstructors()[0]; |
28 | | - var typeConstructorParameters = typeConstructor.GetParameters(); |
29 | | - if (typeConstructorParameters == null || typeConstructorParameters.Length != 1) |
30 | | - continue; |
31 | | - var optionsType = typeConstructorParameters[0].ParameterType; |
32 | | - var name = type.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? type.Name; |
| 23 | + private void register(Type type) |
| 24 | + { |
| 25 | + var typeConstructor = type.GetConstructors()[0]; |
| 26 | + var typeConstructorParameters = typeConstructor.GetParameters(); |
| 27 | + if (typeConstructorParameters == null || typeConstructorParameters.Length != 1) |
| 28 | + return; |
| 29 | + var optionsType = typeConstructorParameters[0].ParameterType; |
| 30 | + var name = type.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? type.Name; |
| 31 | + dict[type.FullName] = new QpClientTypeInfo() |
| 32 | + { |
| 33 | + Name = name, |
| 34 | + QpClientType = type, |
| 35 | + QpClientOptionsType = optionsType |
| 36 | + }; |
| 37 | + } |
33 | 38 |
|
34 | | - dict[type.FullName] = new QpClientTypeInfo() |
35 | | - { |
36 | | - Name = name, |
37 | | - QpClientType = type, |
38 | | - QpClientOptionsType = optionsType |
39 | | - }; |
40 | | - } |
41 | | - } |
| 39 | + public void Init() |
| 40 | + { |
| 41 | + dict = new Dictionary<string, QpClientTypeInfo>(); |
| 42 | + register<Quick.Protocol.Tcp.QpTcpClient>(); |
| 43 | + register<Quick.Protocol.Udp.QpUdpClient>(); |
| 44 | + register<Quick.Protocol.Pipeline.QpPipelineClient>(); |
| 45 | + register<Quick.Protocol.SerialPort.QpSerialPortClient>(); |
| 46 | + register<Quick.Protocol.WebSocket.Client.QpWebSocketClient>(); |
42 | 47 | } |
43 | 48 |
|
44 | 49 | public QpClientTypeInfo Get(string qpClientTypeName) |
|
0 commit comments