You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Reflection;
|
|
|
|
namespace Mesnac.Equips.Connection
|
|
{
|
|
public class Factory
|
|
{
|
|
#region 单例模式
|
|
private static Factory _this;
|
|
public static Factory Instance
|
|
{
|
|
get
|
|
{
|
|
if (null == _this)
|
|
_this = new Factory();
|
|
return _this;
|
|
}
|
|
}
|
|
#endregion
|
|
public ConnType SetConfig(string mode, ConnType connType)
|
|
{
|
|
try
|
|
{
|
|
string className = "Mesnac.Equips.Connection." + mode + ".SetConfigForm";
|
|
Assembly ass = Assembly.GetAssembly(this.GetType());
|
|
Type type = ass.GetType(className);
|
|
if (type == null)
|
|
{
|
|
return null;
|
|
}
|
|
PropertyInfo instance = type.GetProperty("Instance");
|
|
if (instance == null)
|
|
{
|
|
return null;
|
|
}
|
|
return ((ConnConfig)instance.GetValue(type, null)).SetConfig(connType);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
public ConnType GetConfig(XmlNode node)
|
|
{
|
|
string mode = node.Attributes["mode"].Value.ToString();
|
|
try
|
|
{
|
|
string className = "Mesnac.Equips.Connection." + mode + ".SetConfigForm";
|
|
Assembly ass = Assembly.GetAssembly(this.GetType());
|
|
Type type = ass.GetType(className);
|
|
PropertyInfo instance = type.GetProperty("Instance");
|
|
return ((ConnConfig)instance.GetValue(type, null)).GetConfig(node);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|