Basically you would go through and create a shared .dll with your abstract
contract (consider it a "public" dll) ..
as an example .. in my public dll I have an interface IFoo
public interface IFoo {
public void Bar();
}
now in my code I reference the public interface ...
When you want to create your own implementation .. you create your own .dll
.... referencing the public dll and write your own class implementing IFoo.
public class YourFoo : IFoo {
public void Bar() {
Console.WriteLine("YourFoo::Bar()");
}
}
You compile your .dll and place it in my bin folder.
My application simply needs some way of dynamically loading items into its
space, a very common method of doing this is with the factory pattern. Here
is a naive implementation ..
public class FooFactory {
public static IFoo GetFoo(string _AssemblyName, string _TypeName) {
Assembly a = Assembly.LoadFrom(_AssemblyName) ;
return a.CreateInstance(_TypeName) as IFoo;
}
}
So now, we can given an assembly name and a type name dynamically load items
into our process ... now its just a matter of maintaining those. Another
alternative is to use attributes to allow us to discover the types in the
assembly, avoids having to define th assemblyname/typename as we can instead
assume that anything with a FooPlugin attribute is something that we are
interested in.
Hope this helps a bit,
Greg Young
MVP - C#
<fr***********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Nicholas Paldino [.NET/C# MVP] wrote: You could use reflection, but it's not the right way to go on this.
You should do what you said, create an interface, or a base class
which
you derive from which exposes the properties common to all of the
classes.
Then, have your list work with that base class/interface.
Hope this helps.
Yes .. though wondering how to actually go about compiling the new
class without recompilng the existing code and how to add an object
from this class to the list of items.
thanks.