202303241701Change

This commit is contained in:
17860779768
2023-03-24 17:02:04 +08:00
parent 03e8e92c40
commit d12b1b5f2d
19 changed files with 592 additions and 55 deletions

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
using XKRS.Common.Model.Helper;
namespace XKRS.Common.Factory
{
@ -16,7 +17,18 @@ namespace XKRS.Common.Factory
//构造函数退出后,不能分配 readonly 字段。
private static readonly string[] DLLPATTERNS = { "XKRS." };
private static List<Type> types = new List<Type>();
public static List<Type> TYPES
{
get
{
if (types.Count <= 0)
{
types = GetAttributeType<DeviceAttribute>().Values.ToList();
}
return types;
}
}
public static Dictionary<T, Type> GetAttributeType<T>() where T : Attribute
{
@ -59,5 +71,15 @@ namespace XKRS.Common.Factory
});
return attrTyprDict;
}
public static Type GetTypeByAttributeTypeName(string attrTypeName, EnumHelper.DeviceAttributeType attrType)
{
Type type = TYPES.FirstOrDefault(t =>
{
DeviceAttribute attr = t.GetCustomAttribute<DeviceAttribute>();
return attr != null && attr.TypeCode == attrTypeName && attr.AttrType == attrType;
});
return type;
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XKRS.Common.Interface;
using XKRS.Common.Model.Helper;
namespace XKRS.Common.Factory
{
public class UIFactory
{
public static IRunCtrl GetRunCtrl(IDevice device)
{
var attr = device.GetType().GetCustomAttribute<DeviceAttribute>();
if (attr == null)
return null;
var type = FactoryHelper.GetTypeByAttributeTypeName(attr.TypeCode, EnumHelper.DeviceAttributeType.RunCtrl);
if (type == null)
return null;
IRunCtrl runCtrl = Activator.CreateInstance(type, new object[] { device }) as IRunCtrl;
return runCtrl;
}
}
}