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
1
vote
1 answer

Howto Use DynamicMethod.CreateDelegate to return a field value with an instance object

As specified in the question, I am interested in using the Dynamic features of .net to cache an object's field getter/setter and calling it at runtime. Using info from: Is there a way to create a delegate to get and set values for a FieldInfo? I…
1
vote
2 answers

objective c message forwarding with forwardingTargetForSelector not always working

I have a view controller which defines a protocol which itself inherits another protocol. I want any object that implements my protocol to also implement the inherited protocol. I want to set my class to intercept some of the messages in the…
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
2 answers

Using DynamicMethod to invoke a method with generic parameters?

My goal here is to create a method SortRecords that accepts an IEnumerable and a PropertyInfo as parameters. The IEnumerable is a list of records. The PropertyInfo is a property of of T. When invoked, SortRecords should invoke the…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
1
vote
1 answer

Getting an error when I try to use DynamicMethod to create a method that always returns true

Today, I started learning about the DynamicMethod class. For learning purposes, I set about to use DynamicMethod to create a function that takes no argument and always returns the boolean value true. I created a function to do this in C# and then…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
1
vote
0 answers

MSTest Dynamic Methods to Crawl Web Site

I am trying to create a MSTest to crawl a web site. I want it to be dynamic, so I can just throw it into a build for any of our sites. It's basically a step to test before pushing to a staging environment. It checks for broken links and missing…
1
vote
0 answers

DynamicILInfo.GetTokenFor(MethodHandle,RuntimeTypeHandle) does not work for vararg method calls

Consider following code: static public void TestMethodVarArgs(__arglist) { ArgIterator iterator = new ArgIterator(__arglist); Console.WriteLine(iterator.GetRemainingCount()); } static void Main(string[] args) { …
logicnp
  • 5,796
  • 1
  • 28
  • 32
1
vote
1 answer

DynamicMethod.Invoke or DynamicMethod.CreateDelegate+Invoke - which is faster?

Which of the following gives better performance: DynamicMethod dm = .... .. //create IL for 'dm' //store 'dm' for later use .. .. later .. .. dm.Invoke(..); OR DynamicMethod dm; Delegate del = dm.CreateDelegate() // store 'del' for later…
logicnp
  • 5,796
  • 1
  • 28
  • 32
0
votes
1 answer

Create a Field using FieldBuilder and add one to Field Value in MethodBuilder ILCode Emit

I have a Method that creates a MethodBuilder Method and defines the Behaviour using ILGenerator and Emit + OpCodes. This Method was created with the help of a previous StackOverflow Question I made - Thanks to @Marc Gravell for the help The…
0
votes
0 answers

How to add class method dynamically through constructor (PHP). N.B: I do not need method in object (ex: $this->$methodName). not like that

/** * @return string */ public function getCityIdEncryptedAttribute(): string { return encrypt($this->city_id); } I want to generate this method dynamically in the class. not in the object. function __construct…
0
votes
1 answer

Get field value by using DynamicMethod

I'm trying to get the field value by using DynamicMethod instead of Reflection. If I change the field fldTest to static, the code works fine but I need also non-static field. When I run the code as below, the System.InvalidProgramException: 'Common…
Rod
  • 63
  • 6
0
votes
0 answers

Creating Dymamic Method throws en exception

I want to create some dynamic method whcih has 2 cycles: in first some N values are pushed onto evaluation stack, in second - these N values are popped from stack. But CreateMethod throws InvalidProgramException. How I can realize what I want? My…
Tadeusz
  • 6,453
  • 9
  • 40
  • 58
0
votes
1 answer

Call a System.Action in a .NET dynamic method

I have a function that is building a dynamic method. As part of this dynamic method, it is calling an action known at generation time. As a minimal reproducible example, consider the following C# code: using System.Reflection.Emit; static class…
Benji Dial
  • 131
  • 7
0
votes
0 answers

How to do OpCodes.Call properly?

I'm practicing DynamicMethod from this post, and it all worked fine with the following little codes: private delegate long squareDel(int a); squareDel test; private void Form1_Load(object sender, EventArgs e) { DynamicMethod…
PiggyChu001
  • 440
  • 6
  • 20
0
votes
0 answers

Python - how to make dynamic method

I wonder how i can assign dynamic method (for example ".text" or ".split()") to my variable. some_selector = "div.test" # is it possible to add here a method? For example ".text" soup.select_one(some_selector).text # It would work, i want to…
zarize
  • 25
  • 4
0
votes
1 answer

C# calling a public non-static method using reflection without instantiating its class

Is-it possible in C# to call a method (non-static) without instantiating its class e.g : public class MyClass { public void MyMethod() { Console.WriteLine("method called"); } } I've tried this method using the…
Arslan
  • 569
  • 1
  • 4
  • 14