I have one class which i try to create with the help of Avtivator.CreateInstance because i am getting the class name at run time as an string. So, in that class i have some method with one parameter of type List, now my question is how to call this type of method using MethodInfo. e.g.
Class XHospital{
private string HospitalName;
private IList<string> docList;
public void SetDoctorList(List<string> docList){
this.docList = docList;
// some other code snippet here after getting docList
}
// .... rest of the code
}
Now creating Hospital class and calling method
public void SetHospitalDetails(string hospitalName, string methodName){
Type NewType = Type.GetType(hospitalName);
Object NewClass = Activator.CreateInstance(NewClass, new object[]{});
MethodInfo method = NewType.GetMethod(methodName);
IList<string> docs = new List<string>(){ "doc1", "doc2" };
method.Invoke(NewClass, new object[] { docs });//------------- here i am
// getting exception stating ...
/* Object of type 'System.Collections.Generic.List`1[System.Object]'
cannot be converted to type
'System.Collections.Generic.List`1[System.String]' */
}
Please help what i am doing wrong... Note: I am not allow to make any change in XHospital class. So i can't handle it by myself.*** Thanks in advance.