문제

I have a C# solution with 3 projects.

  1. Windows Form Application
  2. Windows Library Module 1 (frmSearch, frmDetail)
  3. Windows Library Module 2 (frmSearch, frmDetail)

Module 1 and Module 2 has two forms each (as shown above). So what I want to do is from Module 2 I need to get Module1.frmDetail, then Instantiate the class and then access its constructor so I can pass a parameter.

The problem is that I don't have an interface of Module1.frmDetail (don't know if I need it), here is my actual code from Module2.frmSearch:

// Use Reflection to load Module1.frmDetail
if(System.Reflection.Assembly.GetEntryAssembly() != null)
{
  System.Reflection.Assembly a = System.Reflection.Assembly.Load("Module1.frmDetail");
  if(a != null)
  {
    System.Type type = a.GetType("Module1.frmDetail");
    var frm = Activator.CreateInstance(type);

    // here i want to pass a parameter to the constructor???

  }
}

Any clue on how to do this?

도움이 되었습니까?

해결책

There's an overload of Activator.CreateInstance that chooses the constructor to call based on the parameters you pass it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top