我在我的课程中编写代码,如下所示,并构建为SmartUser.DLL
namespace SmartUser
{
public class User
{
private static string _companyName = "Company Amazon";
private static string [] _userName = {"Mr. Anam", "Mr. Beat",
"Miss. Jane"};
public static string CompanyName
{
get { return _companyName; }
set { _companyName = value; }
}
public static string[] UserName
{
get { return _userName[]; }
set { _userName= value; }
}
}
}
我使用名为myApp
的方法创建另一个C#项目My_DLL
,以便从SmartUser.DLL
读取数据。
public partial class frmMain : Form
{
public string Licensed_Company;
public string [] Licensed_User;
public void My_DLL()
{
Assembly UserDLL = Assembly.LoadFile(WinForm.Application.StartupPath + @"\User\SmartUser.dll");
Type UserClass = UserDLL.GetType("SmartUser.User");
PropertyInfo company_PropertyInfo = UserClass.GetProperty("CompanyName");
//--- Pass my string CompanyName store in SmartUser to Licensed_Company
Licensed_Company = (string) company_PropertyInfo.GetValue(null, null);
PropertyInfo user_PropertyInfo = UserClass.GetProperty("UserName");
//--- Pass my string CompanyName store in SmartUser to Licensed_Company
Licensed_User[] = (string) user_PropertyInfo.GetValue(null, null);
}
}
我成功读取字符串CompanyName
的数据,但我无法读取字符串数组UserName
那么我该怎样做才能通过名为SmartUser.dll
的方法将数组从My_DLL()
传递到myApp?
感谢提前。
感谢提前。