using System.Reflection;
bool exist = false;
//实体对象
object myResult = null;
int _index = path.IndexOf("Combine");
foreach (object obj in objList)
{
if ((obj as RdoObject).rosPath == path)
{
exist = true;
//(obj as RdoObject).Load();
return (obj as RdoObject); //存在就返回
}
}
Assembly myAssembly = Assembly.GetExecutingAssembly();
string _class = "";
if (exist == false)
{
if (_index < 0)
{
_class = "OMNI.Conf.RDO.RdoObject";
}
else
{
_class = path.Substring(9, path.Length - 10);
_class = "OMNI.Conf.PLU." + _class;
}
Type myType = Type.GetType(_class);
//抽象类
myResult = myAssembly.CreateInstance(_class);
PropertyInfo property1 = myType.GetProperty("rosPath");
property1.SetValue(myResult, path, null);//给对应属性赋值
PropertyInfo property2 = myType.GetProperty("con");
property2.SetValue(myResult, _con, null);//给对应属性赋值
MethodInfo method = myType.GetMethod("Load");
method.Invoke(myResult, null);
objList.Add(myResult);
return myResult;
}
else
{
return myResult;
}