S
sippyuconn
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
((IGlobalSettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
Unable to cast object of type 'UserControls.Setting' to type
'UserControls.ISettings'.
public interface ISettings
{
event EventHandler OnSettingsModified;
}
public Class Settings: UserControl, ISettings
{
private void textEdit_EditValueChanged(object sender, EventArgs e)
{
if (OnSettingsModified != null)
{
OnSettingsModified.Invoke(sender, e);
}
}
}
My App
======
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType.FullName.Contains("ISettings"))
{
object obj =
(IGlobalSettings)Activator.CreateInstance(type) as object;
((IGlobalSettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
}
}
}
}
private void Configuration_OnValid(object sender, System.EventArgs e)
{
UpdateEnableSave();
}
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
((IGlobalSettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
Unable to cast object of type 'UserControls.Setting' to type
'UserControls.ISettings'.
public interface ISettings
{
event EventHandler OnSettingsModified;
}
public Class Settings: UserControl, ISettings
{
private void textEdit_EditValueChanged(object sender, EventArgs e)
{
if (OnSettingsModified != null)
{
OnSettingsModified.Invoke(sender, e);
}
}
}
My App
======
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType.FullName.Contains("ISettings"))
{
object obj =
(IGlobalSettings)Activator.CreateInstance(type) as object;
((IGlobalSettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
}
}
}
}
private void Configuration_OnValid(object sender, System.EventArgs e)
{
UpdateEnableSave();
}