Hi
Trying to use Reflection to Create a UserControl then get at Interface on
UserControl which defines an Event. Then add that Event to EventHandler
But looks like I am getting exception on Cast ???
Thanks
On this statment - I get Exception
((IGlobalSettin gs)obj).OnSetti ngsModified += new
EventHandler(Co nfiguration_OnV alid);
Unable to cast object of type 'UserControls.S etting' to type
'UserControls.I Settings'.
public interface ISettings
{
event EventHandler OnSettingsModif ied;
}
public Class Settings: UserControl, ISettings
{
private void textEdit_EditVa lueChanged(obje ct sender, EventArgs e)
{
if (OnSettingsModi fied != null)
{
OnSettingsModif ied.Invoke(send er, e);
}
}
}
My App
======
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfa ces())
{
if (interfaceType. FullName.Contai ns("ISettings") )
{
object obj =
(IGlobalSetting s)Activator.Cre ateInstance(typ e) as object;
((IGlobalSettin gs)obj).OnSetti ngsModified += new
EventHandler(Co nfiguration_OnV alid);
}
}
}
}
private void Configuration_O nValid(object sender, System.EventArg s e)
{
UpdateEnableSav e();
}
Trying to use Reflection to Create a UserControl then get at Interface on
UserControl which defines an Event. Then add that Event to EventHandler
But looks like I am getting exception on Cast ???
Thanks
On this statment - I get Exception
((IGlobalSettin gs)obj).OnSetti ngsModified += new
EventHandler(Co nfiguration_OnV alid);
Unable to cast object of type 'UserControls.S etting' to type
'UserControls.I Settings'.
public interface ISettings
{
event EventHandler OnSettingsModif ied;
}
public Class Settings: UserControl, ISettings
{
private void textEdit_EditVa lueChanged(obje ct sender, EventArgs e)
{
if (OnSettingsModi fied != null)
{
OnSettingsModif ied.Invoke(send er, e);
}
}
}
My App
======
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfa ces())
{
if (interfaceType. FullName.Contai ns("ISettings") )
{
object obj =
(IGlobalSetting s)Activator.Cre ateInstance(typ e) as object;
((IGlobalSettin gs)obj).OnSetti ngsModified += new
EventHandler(Co nfiguration_OnV alid);
}
}
}
}
private void Configuration_O nValid(object sender, System.EventArg s e)
{
UpdateEnableSav e();
}
Comment