R
rowe_newsgroups
I know this has to be answered in the archives somewhere, but the
search results are just confusing me more :-(
Anyways, I authored a control library that contains an Interface
definition and then some usercontrols that implement that interface.
In a separate project I want to load the dll and then load the
usercontrols onto tabpages on my form.
I just cannot seem to figure out how to cast the usercontrols into the
interface type so I can access the defined methods.
Here's the interface thats defined only in the dll:
public interface IReadonlyTab
{
void CreateBindings();
String CaptionText { get;}
String ConnectionString { get;set;}
event RequestTitleChangeEventHandler RequestTitleChange;
}
And here's the nonworking code that loads the controls:
String path = @"C:\Documents and Settings\srowe\Desktop
\MyTabs.dll";
Assembly assembly = Assembly.LoadFrom(path);
Type[] types = assembly.GetTypes();
foreach (Type t in types)
{
Type I = t.GetInterface("MainTabs.IReadonlyTab");
if (I != null)
{
//I want to do something similar to this:
Type.GetType(I) c =
(Type.GetType(I))Activator.CreateInstance(t);
TabPage tp = new TabPage(c.CaptionText); //CaptionText is
an Interface defined property
tp.Controls.Add(c);
this.tabControl1.TabPages.Add(tp);
}
}
In case you haven't realized I'm new to using reflection, so please be
nice if I'm missing something obvious here.
I really appreciate any advice you experts can give!
Thanks,
Seth Rowe
search results are just confusing me more :-(
Anyways, I authored a control library that contains an Interface
definition and then some usercontrols that implement that interface.
In a separate project I want to load the dll and then load the
usercontrols onto tabpages on my form.
I just cannot seem to figure out how to cast the usercontrols into the
interface type so I can access the defined methods.
Here's the interface thats defined only in the dll:
public interface IReadonlyTab
{
void CreateBindings();
String CaptionText { get;}
String ConnectionString { get;set;}
event RequestTitleChangeEventHandler RequestTitleChange;
}
And here's the nonworking code that loads the controls:
String path = @"C:\Documents and Settings\srowe\Desktop
\MyTabs.dll";
Assembly assembly = Assembly.LoadFrom(path);
Type[] types = assembly.GetTypes();
foreach (Type t in types)
{
Type I = t.GetInterface("MainTabs.IReadonlyTab");
if (I != null)
{
//I want to do something similar to this:
Type.GetType(I) c =
(Type.GetType(I))Activator.CreateInstance(t);
TabPage tp = new TabPage(c.CaptionText); //CaptionText is
an Interface defined property
tp.Controls.Add(c);
this.tabControl1.TabPages.Add(tp);
}
}
In case you haven't realized I'm new to using reflection, so please be
nice if I'm missing something obvious here.
I really appreciate any advice you experts can give!
Thanks,
Seth Rowe