Questions tagged [dynamicmethod]

DynamicMethod is a .Net class that can be used to define a method at runtime using CIL.

System.Reflection.Emit.DynamicMethod is a .Net class that can be used to define a method at runtime using .

115 questions
53
votes
1 answer

Curiosity: Why does Expression<...> when compiled run faster than a minimal DynamicMethod?

I'm currently doing some last-measure optimizations, mostly for fun and learning, and discovered something that left me with a couple of questions. First, the questions: When I construct a method in-memory through the use of DynamicMethod, and use…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
20
votes
2 answers

Practical example of Dynamic method?

I want to learn dynamic method and its practical example using c#. Is there any relation between dynamic method and Reflection? Please help me.
Pankaj
  • 4,419
  • 16
  • 50
  • 72
13
votes
2 answers

How do I dynamically invoke methods in Groovy?

At runtime I'm grabbing a list of method names on a class, and I want to invoke these methods. I understand how to get the first part done from here: http://docs.codehaus.org/display/GROOVY/JN3535-Reflection GroovyObject.methods.each{ println…
avgvstvs
  • 6,196
  • 6
  • 43
  • 74
12
votes
5 answers

How do I get an IL bytearray from a DynamicMethod?

As a bit of a novelty, I'm trying to see how different the IL from light weight code generated at runtime looks vs code generated by the VS compiler, as I noticed that VS code tends to run with a different performance profile for things like…
Michael B
  • 7,512
  • 3
  • 31
  • 57
10
votes
2 answers

DynamicMethod is much slower than compiled IL function

I wrote a simple object copier that copies public properties. I can't figure out why the Dynamic method is a lot slower than the c# version. Durations C# method : 4,963 ms Dynamic method : 19,924 ms Note that - as I run the dynamic method before…
Pascal Ganaye
  • 1,174
  • 12
  • 28
9
votes
1 answer

Dynamic Assemblies and Methods

I've programmed .NET and C# for years now, but have only recently encountered the DynamicMethod type along with the concept of a Dynamic Assembly within the context of reflection. They seem to always be used within IL (runtime code)…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
9
votes
1 answer

How to use SuperObject to invoke methods that uses an Object as parameter in Delphi?

We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer I'd like to know how do I send a created object as a parameter. I tried to…
Haruki
  • 674
  • 1
  • 9
  • 24
9
votes
2 answers

DynamicMethod and type checks

Can someone explain or point to explanation why runtime types check not occurs in sample below - string property can be set to any type value ... Stuck with this in very unexpected place and was really surprised using System; using…
Alex A
  • 141
  • 6
9
votes
1 answer

DynamicMethod and out-parameters?

How do I define a DynamicMethod for a delegate that has an out-parameter, like this? public delegate void TestDelegate(out Action a); Let's say I simply want a method that sets the a argument to null when I call the method. Note that I know that a…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
8
votes
2 answers

DynamicMethod with generic type parameters

Is it possible to define a DynamicMethod with generic type parameters? The MethodBuilder class has the DefineGenericParameters method. Does the DynamicMethod have a counterpart? For example is it possible to create method with a signature like the…
Alex
  • 2,040
  • 2
  • 19
  • 29
8
votes
2 answers

Is it possible to use Reflection.Emit for the opcodes stelem.any and ldelem.any?

So, I recently did some experimenting and discovered that it appears that Reflection.Emit doesn't support all of the opcodes in the ECMA spec. There are 3 opcodes missing: ldelem.any stelem.any no. (prefix) Are these opcodes just not supported in…
Earlz
  • 62,085
  • 98
  • 303
  • 499
7
votes
2 answers

Saving a DynamicMethod to disk

I have inherited code that uses DynamicMethod to generate methods at runtime. I also need to modify some of the code that is being generated. Since I am a n00b at MSIL, I would love to be able to load the generated code up in Reflector and ensure…
Mike Caron
  • 14,351
  • 4
  • 49
  • 77
6
votes
1 answer

ILGenerator: How to use unmanaged pointers? (I get a VerificationException)

I'm making a sound synthesis program in which the user can create his own sounds doing node-base compositing, creating oscillators, filters, etc. The program compiles the nodes onto an intermediary language which is then converted onto an MSIL via…
Rafael
  • 2,642
  • 2
  • 24
  • 30
6
votes
6 answers

Runtime code injection using DynamicMethod?

Consider the following trivial code: using System; class Test { delegate int FooDelegate(int i); FooDelegate Foo = FooImplementation; static int FooImplementation(int i) { return i + 1; } public static void…
The Fiddler
  • 2,726
  • 22
  • 28
6
votes
1 answer

Resolving the tokens found in the IL from a dynamic method

Thanks to Hans Passant answering my question here: How do I get an IL bytearray from a DynamicMethod? I was able to get up and running. I am now trying to resolve the Metadata tokens found in the IL emitted, to see what methods are being called, or…
Michael B
  • 7,512
  • 3
  • 31
  • 57
1
2 3 4 5 6 7 8