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;
|
}
|
}
|
}
|