From e57938fbda9bff702004038f76d009422968bff5 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 06 十一月 2026 18:05:07 +0800
Subject: [PATCH] 提交代码
---
DeviceService/DeviceConfigControlFactory.cs | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/DeviceService/DeviceConfigControlFactory.cs b/DeviceService/DeviceConfigControlFactory.cs
new file mode 100644
index 0000000..bbe1dc2
--- /dev/null
+++ b/DeviceService/DeviceConfigControlFactory.cs
@@ -0,0 +1,36 @@
+using DeviceService.Core;
+using System.Reflection;
+using System.Windows.Controls;
+
+namespace DeviceService
+{
+ /// <summary>
+ /// 鎸夊懡鍚嶈鍒欏垱寤鸿澶囬厤缃帶浠讹細璁惧绫诲悕 CanDevice 瀵瑰簲 CanDeviceConfigControl銆�
+ /// </summary>
+ public static class DeviceConfigControlFactory
+ {
+ public static UserControl? Create(IDevice device)
+ {
+ if (device == null) throw new ArgumentNullException(nameof(device));
+
+ string controlName = device.GetType().Name + "ConfigControl";
+
+ try
+ {
+ Type? type = typeof(DeviceConfigControlFactory).Assembly.GetTypes()
+ .FirstOrDefault(t => t.Name == controlName
+ && typeof(UserControl).IsAssignableFrom(t)
+ && !t.IsAbstract);
+
+ return type == null ? null : (UserControl?)Activator.CreateInstance(type);
+ }
+ catch (ReflectionTypeLoadException ex)
+ {
+ Type? type = ex.Types.FirstOrDefault(t => t?.Name == controlName
+ && typeof(UserControl).IsAssignableFrom(t)
+ && !t.IsAbstract);
+ return type == null ? null : (UserControl?)Activator.CreateInstance(type);
+ }
+ }
+ }
+}
--
Gitblit v1.9.1