Re: Dynamic class creation at runtime
- From: "Piggy" <Piggy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 11 Jul 2005 06:27:03 -0700
Hi Jon,
thank you very much for your reply. My problem is not about creating an
instance of a type I am already doing this, now I would like to create
dinamically a new type that inherit directly from the base class. The new
type has to override a function of the base type, and the code of the
override is to be provided by the user at runtime. I also need to save the
new class.
Just for example:
I have in my assembly the base class and 2 inherited classes: BaseClass,
Class1 and Class2
At runtime I want to create Class3 (that inherits directly from the
BaseClass), just by typing the new code for the mustoverride function of the
BaseClass, and saving it. After doing that I need to be able to use (at
runtime) class3 in the same way I use Class1 and Class2.
Can you help me with this?
Thank you very much
"Jon Skeet [C# MVP]" wrote:
> Piggy <Piggy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > I?m developing a project in VB.NET 2003 to analyze the financial markets
> > using several algorithms. To do that I created a ?mustinherit? class to
> > manage the behavior of the standard algorithm, and then a number of inherited
> > classes for each single algorithm.
> > Since the algorithms are potentially infinite, I will never be able to code
> > them all in the project at design time. So, I would like now to create an
> > editor to allow the users (using my software GUI) to dynamically create a new
> > class (inherited from the generic class) for each algorithm they want to use.
> > I do not have any idea on how I can do it. I read something about the
> > dynamic definition of Assemblies, but I do not want to create a new Assembly,
> > I would only add (and save) a new inherited class to my existing assembly.
> > Any help (samples, ideas, links) will be greatly appreciated.
>
> I'm not entirely sure which bit is causing you problems, but
> Activator.CreateInstance is the way to go for creating new instances of
> a type which is only known at runtime. You can find all the types in an
> assembly which inherit from a given base class by using
> Assembly.GetTypes and then checking IsAssignableFrom for each type,
> passing in the base class. (This is better than using the BaseType
> property, as that will only find classes that inherit directly from the
> base class.)
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>
.
- Follow-Ups:
- Re: Dynamic class creation at runtime
- From: Jon Skeet [C# MVP]
- Re: Dynamic class creation at runtime
- References:
- Dynamic class creation at runtime
- From: Piggy
- Re: Dynamic class creation at runtime
- From: Jon Skeet [C# MVP]
- Dynamic class creation at runtime
- Prev by Date: RE: http errors.....
- Next by Date: Re: Dynamic class creation at runtime
- Previous by thread: Re: Dynamic class creation at runtime
- Next by thread: Re: Dynamic class creation at runtime
- Index(es):
Relevant Pages
|