悬赏分:15 浏览:349 次
这个反射是该怎么写的呀?
Register是CommonUserOperation类下的方法,ICommonUser接口
CommonUserProperty继承了这个接口,
,我想用反射得到所有属性值,
红颜色 Load()该怎么写呀?我看了MSDN要加引用,不明白,请指点。
public bool Register(ICommonUser user)
{
Assembly theAssembly = Assembly.Load(user.ToString());
if (theAssembly == null) return false;
Type type = theAssembly.GetType();
PropertyInfo[] myProperty = type.GetProperties();
object[] param = new object[myProperty.Length];
//param = myProperty.CopyTo(param, 0);
for (int i = 0; i < myProperty.Length; i++)
{
param[i] = myProperty[i].GetValue(myProperty, null);
}
DiseaseDetails dis = new DiseaseDetails();
return (bool)dis.Execute("CommonUserRegister", "int", param);
}
上面代码调用时出错:"未能加载文件或程序集“UserRegister.CommonUserProperty”或它的某一个依赖项。系统找不到指定的文件。"
|
Assembly.Load(string assemblyName)的参数是程序集的名字,而不是一个类的名字。
请参考:http://msdn.microsoft.com/zh-cn/library/ky3942xh(VS.80).aspx 我觉得用Assembly.Load来载入程序集, 和使用Type来加载,我觉的是不是应该Type性能更好? Type应该是直接加载Bin目录下的DLL,而Bin目录下的应该是以及被保存在缓存中了。而Assmebly.Load应该是去相应目录去找程序集,然后加载的吧 ?? SampleAssembly = Assembly.Load(“Cigem.SQLServerDAL.Account”); 其中,Account为类。 这里要求你的dll是强制签名的,否则会报错。未能加载文件或程序集... // Assembly.Load("Cigem.SQLServerDAL, 1.0.0.0, neutral, 6c13c48089e0ee07") |