S
sippyuconn
Hi
Creating an Control Thru Refelection that also has an Interface on it
I can create the Control but when I try to get an Instance of Interface get
exception that cannot
Unable to cast object of type 'UserControls.UserControl2' to type
'UserControls.ISettings'.
Any ideas why ???
Thanks
UserControl
=========
namespace UserControls
{
public partial class UserControl2 : UserControl, ISettings
{
public event EventHandler OnSettingsModified;
}
}
Reflection to get to Interface
====================
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType.FullName.Contains("ISettings"))
{
bClass = true;
break;
}
}
if(bClass)
{
Control control = Activator.CreateInstance(type)
as Control;
try
{
object obj = Activator.CreateInstance(type)
as object;
((ISettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
}
catch() {}
Creating an Control Thru Refelection that also has an Interface on it
I can create the Control but when I try to get an Instance of Interface get
exception that cannot
Unable to cast object of type 'UserControls.UserControl2' to type
'UserControls.ISettings'.
Any ideas why ???
Thanks
UserControl
=========
namespace UserControls
{
public partial class UserControl2 : UserControl, ISettings
{
public event EventHandler OnSettingsModified;
}
}
Reflection to get to Interface
====================
foreach (Type type in asm.GetTypes())
{
if (type.IsClass == true )
{
bClass = false;
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType.FullName.Contains("ISettings"))
{
bClass = true;
break;
}
}
if(bClass)
{
Control control = Activator.CreateInstance(type)
as Control;
try
{
object obj = Activator.CreateInstance(type)
as object;
((ISettings)obj).OnSettingsModified += new
EventHandler(Configuration_OnValid);
}
catch() {}