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
2
votes
3 answers

Reflection or DynamicMethod?

I have used NHibernbate in few projects and now learned about few more ORMs also. I understand that, NHibernate binds Class to Datalayer dynamically during runtime using the mapping file. My Question is , how this late binding is done ? I mean,…
Palani
  • 8,962
  • 11
  • 53
  • 62
2
votes
0 answers

Is it possible to force the compilation of DynamicMethod without hacking?

I'm working on a Json serialization solution. I found out that the serialization based on emitting was much faster than direct operations on Reflection api after the emitted code had already been run once(each time with different data). Obviously…
2
votes
1 answer

How to call DynamicMethod in DynamicMethod

How do I emit IL to call a DynamicMethod while creating a DynamicMethod? When calling ILGenerator.Emit(OpCodes.Callvirt, myDynamicMethod); the IL that is produces results in a MissingMethodException when executed. I reproduced the issue with this…
Sellorio
  • 1,806
  • 1
  • 16
  • 32
2
votes
0 answers

Call method via DynamicMethod - Reflection.Emit

I've got a slightly modified class of this answer in order to dynamically call TryParse of various types (char, int, long). public delegate TRet DynamicMethodDelegate(object target, params object[] args); public delegate void…
Blacktempel
  • 3,935
  • 3
  • 29
  • 53
2
votes
1 answer

How to represent typeof(Int32&) type in DynamicMethod Emit

I have the following code: delegate void RefAction(ref Int32 i);// use ref keyword static RefAction CreateRefGenerator(){ // How to represent typeof(Int32&)type in here?? Type[] types ={ typeof(Int32)}; var dm = new…
Ko.Y
  • 325
  • 1
  • 2
  • 7
2
votes
1 answer

Make DynamicMethod call other method

I want to be able to subscribe to any event of any object by passing event's name and Action dependent on client code. I have following code public static class EventSubscriber { public static object Subscriber( this object…
Andriy Shevchenko
  • 1,117
  • 6
  • 21
2
votes
1 answer

c# + Using dynamicmethod with an attribute

[CustomAttribute] public bool IsGreen() { return true; } How could one write the above using a DynamicMethod in c#? UPDATE; per casperOne you cannot do this with a custom attribute. But what about a non-custom attribute such…
schmoopy
  • 6,419
  • 11
  • 54
  • 89
2
votes
2 answers

How can I make my DynamicMethod security-critical?

I have a rather convoluted scenario where I want to create a DynamicMethod that's attached to a class in an in-memory AssemblyBuilder. The dynamic method calls a method "GetReplacement" in a (regular) assembly of mine. This worked fine in .NET 2.0,…
mcobrien
  • 1,130
  • 1
  • 9
  • 16
2
votes
3 answers

Why does calling a DynamicMethod with an instance of my own class cause an exception?

I'm learning CIL by making my own functions at runtime with Reflection.Emit. I'm actually surprised how easy things have been up until now but I've hit something that I can't guess my way through and I can't find anything relative in the docs. I'm…
PythonPower
2
votes
1 answer

How to convert a POCO into array using CIL?

This is the first time I'm dabbling with generated CIL, so please bear with my ignorance. I'm looking for a simple DynamicMethod that can read the fields of a POCO, and fill them into an object[]. No type conversion is necessary. I've put together…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
2
votes
1 answer

What's the simplest way of adding state to CLR's DynamicMethod?

I'm doing a little code generation with DynamicMethod and I have a problem that would be handily solved by adding a little state, like a field. Unfortunately, I can't push this state into one of the method's parameters, so I basically need to close…
naasking
  • 2,514
  • 1
  • 27
  • 32
2
votes
1 answer

prevent DynamicMethod VerificationException - operation could destabilize the runtime

I am using IL generation to create a simple deserializer method which takes strings out of a Lucene document and sets properties or fields of a reference-type object (POCO). Whenever I try to run the generated method, I receive a…
Leland Richardson
  • 2,695
  • 2
  • 20
  • 27
2
votes
1 answer

How to add Custom Attributes to a DynamicMethod-generated method?

I was playing around with DynamicMethod and Expression Trees' Compilation (which uses DynamicMethod internally). I then wondered if there is a way to add a custom attribute to the generated method. I googled about it, but I couldn't find a way. I…
jpbochi
  • 4,366
  • 3
  • 34
  • 43
2
votes
1 answer

Get value of static field via dynamic method

I've got the following class: public class TestClass { public static readonly string HELLO = "Hello, "; public static string SayHello(string name) { return HELLO + name; } } And I want to access the static field of…
1
vote
1 answer

Adding description to dynamically generated methods in Reflection.Emit

I have used Reflection.Emit to dynamically generate some types and methods. Everything works fine, but I want to include some descriptive information with the method so that others can use it more easily. You would normall do this by including…
j0nnyl33
  • 13
  • 2