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

C# - Reflection.Emit: Return reference to a local variable

I want to make a DynamicMethod which in turn behave like the following for example: AnyClass myClass = new AnyClass(); Func myFunc = () => myClass; I know that when I want to make it work with an int instead of AnyClass I have to use the…
Dragonblf
  • 115
  • 1
  • 8
0
votes
0 answers

Calling class methods dinamically using Python

A functional example (out of class) for a better explanation about what I'm trying to get. def greet(): print('Hello world') func = 'greet' func() But, if I use same example as a class method, I cannot get the same result. I understand Python…
Carlos Diaz
  • 321
  • 1
  • 15
0
votes
1 answer

C# - Reflection.Emit : Return result of called method

In a DynamicMethod I try to call a method that wants an array of objects to return the length of the given array. Currently, my method which should be called from the DynamicMethod looks like the following: public static int Test(Object[] args) { …
Dragonblf
  • 115
  • 1
  • 8
0
votes
0 answers

Getting a "Common Language Runtime detected an invalid program." error when trying to map ReadUnaligned using DynamicMethod and ILGenerator

I'm trying to map the IL code for ASP.CORE method ReadUnaligned as defined here in .NET Frameword using DynamicMethod following this example. When trying to run the code, I get the "Common Language Runtime detected an invalid program." error. My…
Catalin Florea
  • 468
  • 8
  • 16
0
votes
1 answer

how can i call method dynamically in react hooks

In my React hooks I defined two functions for setting variables: setProjectMiddleCode and setProjectToolCode. I hope to call this two method in my react hooks to avoid duplicate code. I would like to do it like this: //variable define let data; let…
dondon
  • 3
  • 2
0
votes
1 answer

Create weak delegate of Dynamic Method(ref object,object[] arr)

Source code:https://www.pastefile.com/4mzhyg I'm trying to create delegate of format: public delegate TReturn MethodCallerR(ref TTarget target, object[] args); /// /// Generates a strongly-typed open-instance…
user999913
  • 336
  • 2
  • 8
0
votes
0 answers

Converting IL method to C# code using De-Serialization

May be it's dump question because i am new to DynamicMethod so Please guide me. I have C# method store which is serialized in binary file. Data stored is in this fashion . Token: 6000196 // Meta Token Flags: 2 MaxStack: 8 LocalVarsSig: null Code:…
user81907
  • 25
  • 7
0
votes
0 answers

Regular expression-like pattern matching on IEnumerable instead of string chars in C#

I am trying to modify a list of CIL code instructions in C#. Common tasks include finding groups or patterns of instructions and replacing them with other instructions while reusing some of the information from the original match. That sounds a lot…
Andreas Pardeike
  • 4,622
  • 1
  • 17
  • 27
0
votes
1 answer

Does DynamicMethod 'skipVisibility' have a performance penalty?

When creating a DynamicMethod in C# for which bypassing visibility is not necessary or irrelevant, what is the best value to specify for the skipVisibility parameter of the DynamicMethod constructor? Is there a performance penalty, i.e., associated…
Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108
0
votes
0 answers

How can i capture local variable in dynamic method?

(I'm new to english) I use Expression.Lambda for dynamically creating lambda. I want capture variables but i don't know how to capture using Expression. public class Demo { /** skip */ private Context _context; …
0
votes
1 answer

How to mark DynamicMethod as SecurityCritical?

I'm using a slightly modified version of this TaskFromEvent method. It basically creates a Task that completes when the Event fires. This is made possible by using DynamicMethod and emitting IL code. When I do some simple tests in dummy environment,…
m93a
  • 8,866
  • 9
  • 40
  • 58
0
votes
1 answer

DynamicMethod - Common language runtime detected an invalid program

So I try to call a method from an extern DLL via a dynamicmethod using the ilgenerator. delegate void Write(string text); static void Main(string[] args) { byte[] bytes = File.ReadAllBytes(@"externmethod.dll"); var assembly =…
0
votes
1 answer

Dynamic Method OpCodes.Stfld causing 'Operation could destabilize the runtime'

I'm trying to upgrade a .Net 3.5 project to .Net 4.5, everything is working, but one DynamicMethod is causing an 'Operation could destabilize the runtime' exception public static FieldSetter CreateSetFieldDelegate(FieldInfo…
Failwyn
  • 767
  • 8
  • 22
0
votes
2 answers

How can I create a dynamic method to handle an event?

In C#, how can I create a dynamic method that can be used to handle an event? Here is an event: public event EventHandler refresh; Here is a method: public void Test() { } How can I dynamically create a method to handle the refresh…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

Call a method when a generic event occurs

I'm facing a problem when trying to implement a call to a method fired up by an event which should be defined during run-time. I found this answer: Redirecting to a dynamic method from a generic event handler and implemented that solution, but I…