S
sippyuconn
Hi
I have an Assembly that has various usercontrols that all implemnet
an Interface
The Interface
public interface ISettings
{
bool SaveSettings();
}
I then have a test pgm that will loop thru the asssmbly and find all classes
that implement the ISettings interface. I then display all the UserControls
on a Form
Assembly asm = Assembly.LoadFrom(@"C:\myUserContro.dll");
// Walk through each type in the assembly looking for our
class
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;
xtraTabControl1.TabPages.Add();
xtraTabControl1.TabPages[xtraTabControl1.TabPages.Count - 1].Text =
type.FullName;
xtraTabControl1.TabPages[xtraTabControl1.TabPages.Count-1].Controls.Add(control);
}
}
This is all fine
The question is on the form where I create the UserControls I have a "SAVE"
button. When I hit the SAVE button I want to fire all the interface method
"SaveSettings" from all the UserControls.
What is the best way to do that???
Thanks
I have an Assembly that has various usercontrols that all implemnet
an Interface
The Interface
public interface ISettings
{
bool SaveSettings();
}
I then have a test pgm that will loop thru the asssmbly and find all classes
that implement the ISettings interface. I then display all the UserControls
on a Form
Assembly asm = Assembly.LoadFrom(@"C:\myUserContro.dll");
// Walk through each type in the assembly looking for our
class
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;
xtraTabControl1.TabPages.Add();
xtraTabControl1.TabPages[xtraTabControl1.TabPages.Count - 1].Text =
type.FullName;
xtraTabControl1.TabPages[xtraTabControl1.TabPages.Count-1].Controls.Add(control);
}
}
This is all fine
The question is on the form where I create the UserControls I have a "SAVE"
button. When I hit the SAVE button I want to fire all the interface method
"SaveSettings" from all the UserControls.
What is the best way to do that???
Thanks