I am trying creating a class dynamically at runtime with
Activator.CreateInstance(ObjType); where ObjType is retrieved through
foreach (Type tipo in ass.GetTypes())
{
ObjType=tipo.GetType();
tmp=(IPlugin)Activator.CreateInstance(ObjType);
}
ObjType is "linked" with per example this class
public class PersonaUserControlController:AbstractUserControlController
{
private IAlumnosUseCase model;
private IPersonaUserControl view;
public PersonaUserControlController()
{
//
// TODO: Add constructor logic here
//
this.model =
(IAlumnosUseCase)UseCaseFactory.getInstance().getUseCase("AlumnosUseCase");
this.view =
(IPersonaUserControl)UserControlFactory.getInstance().getUserControl("PersonaUserControl");
plugin_name = "PersonaUserControl";
ConfigureMenu();
}
...more methods but only one constructor
}
/***************************************************************/
I think this could help....
abstract public class
AbstractUserControlController:AbstractPlugin,IUserControlController
{
}
abstract public class AbstractPlugin:IPlugin
{
}
/***************************************************************/
Why did exception raises if one constructor exists and without parameters?
Thanks in advance
| I am trying creating a class dynamically at runtime with
| Activator.CreateInstance(ObjType); where ObjType is retrieved through
|
| foreach (Type tipo in ass.GetTypes())
| {
| ObjType=tipo.GetType();
| tmp=(IPlugin)Activator.CreateInstance(ObjType);
| }
I think your problem is that you are getting the type of System.Type !!
foreach (Type tipo in ass.GetTypes())
{
// assuming tipo now contains the type that you want to create...
| ObjType=tipo.GetType();
// ObjType now contains System.Type as that would be the type of tipo.
| tmp=(IPlugin)Activator.CreateInstance(ObjType);
| }
I think you need to remove one line of code like this :
foreach (Type tipo in ass.GetTypes())
{
tmp=(IPlugin)Activator.CreateInstance(tipo);
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer