overwrite method in class at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to be able to write a method that varies from instance to instance of
a class. Basically I have a formula class. Somebody inputs a formula and I
parse it and generate the code to calculate it. I have looked at
Reflections.Emit. The problem is that it requires creating a new type
everytime you want to create a new procedure. This could be very costly as
there can be many formulas. Is there a way to generate only a method and get
a pointer for it, and call it from within my class or some other workaround
for this? Thanks.


Landagen
 
OK, i figured out a workaround using MethodRental. Its not exactly what I
want, but it is sufficient. If anybody has a better idea, please let me know.
 
landagen said:
OK, i figured out a workaround using MethodRental. Its not exactly what I
want, but it is sufficient. If anybody has a better idea, please let me
know.

Unfortunatly, I don't believe there is anything better.

In the 2.0 framework, there is a way to generate 'Dynamic Methods' which are
garbage collected delegates. MethodRental is the best you are going to find
until then, however.
 
Back
Top