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
0
votes
0 answers

How to implement shallowcopy with IL (C#)?

I want to implement a shallow copy with C# IL instead of reflection directly. • ShallowCopy version with reflection directly: public T ShallowCopy(T instanceToShallowCopy) where T : class { Type type =…
Jason Cai
  • 1
  • 1
  • 1
  • 2
0
votes
1 answer

How to pass value when subscribing to event and obtain it when the event is triggered (DynamicMethod usage problems)

The task is to create event handlers in runtime. I need the one method to be called with different parameter value for different events. The events and their number are only known in runtime. So I'm trying to generate dynamic methods, each of which…
Yegor
  • 2,514
  • 2
  • 19
  • 27
0
votes
1 answer

How to call a dynamic method to return square of number?

I want to create a simple dynamic method that returns square of a integer number(i.e - If number is 5, it should return 25). I have written the code below:- class Square { public int CalculateSquare(int value) { return value * value;…
K P
  • 31
  • 6
0
votes
1 answer

JIT Compiler error - Invalid Program Exception using Reflection.Emit

Can someone explain to me why the following works for the first test but throws an InvalidProgramException for the second test? I'm stumped. using System; using System.Reflection; using System.Reflection.Emit; namespace DMTest { class Program …
0
votes
2 answers

DynamicMethod NullReferenceException

Can anyone tell me what's wrong with my IL code here? IL_0000: nop IL_0001: ldarg.1 IL_0002: isinst MyXmlWriter IL_0007: stloc.0 IL_0008: ldloc.0 IL_0009: ldarg.2 IL_000a: ldind.ref IL_000b: unbox.any TestEnum IL_0010:…
Jeff
  • 1
  • 2
0
votes
1 answer

How to invoke Nullable.HasValue in DynamicMethod?

I'm writing some code using DynamicMethod. Inside my DynamicMethod, I want to invoke the Nullable.HasValue (and also the Nullable.Value) properties. I've written some code to do some, but I keep getting the Operation could destabilize the runtime…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
0
votes
1 answer

How to factor type parameters out of my code that uses DynamicMethod and Entity Framework?

I am creating a framework that is meant to allow web developers to create CRUD pages without having to go thru repetitive steps. To that end, I want to provide "default" methods that do things like sorting, filtering, and the like. A developer…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
0
votes
1 answer

Access Violation with Dynamic Method, only when Running 32 Bit

I have the following code for creating a dynamic method to call the Set method of a property in my VB.net app, using .NET 3.5 (can't switch to the Lambda expression style). Using an the example posted here, I added to the function because it did not…
Kratz
  • 4,280
  • 3
  • 32
  • 55
0
votes
1 answer

Grails addTo and removeFrom dynamic methods performance

I have been using Grails addTo and removeFrom dynamic methods and they are awesome, Usually I use them in following way String id =params.quizId Quiz quizInstance = Quiz.get(Long.parseLong(id))// **1** for( String q in params.questionCheckBox) { …
Sap
  • 5,197
  • 8
  • 59
  • 101
-5
votes
1 answer

System.Reflection.Emit::DynamicMethod: Is there a tool to have IL code generated from existing assembly?

I want to create a dynamic method with code that's a bit more than trivial. So I want to create a hard coded version of the method body and have a compiled version of it examined by some tool that's returning OpCos and parameters to me so I can…
AxD
  • 2,714
  • 3
  • 31
  • 53
1 2 3 4 5 6 7
8