从嵌入式DLL中读取数组c#

时间:2016-09-19 03:22:36

标签: c# arrays dll embedded

我在我的课程中编写代码,如下所示,并构建为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?

感谢提前。

感谢提前。

0 个答案:

没有答案