Questions tagged [dynamic-method]

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 .

46 questions
72
votes
5 answers

Dynamic method calling in Ruby

As far as I am aware there are three ways to dynamically call a method in Ruby: Method 1: s = SomeObject.new method = s.method(:dynamic_method) method.call Method 2: s = SomeObject.new s.send(:dynamic_method) Method 3: s = SomeObject.new eval…
Abraham P
  • 15,029
  • 13
  • 58
  • 126
16
votes
1 answer

What are dynamic methods and how is DynamicMethod different from MethodBuilder?

I've come across dynamic methods a little in reflection-based C# code, and I'm yet to figure out precisely what they are. There specifically seems to be a DynamicMethod class that allows the generation and specification of CLR methods at runtime.…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
11
votes
2 answers

Passing a lambda to a secondary AppDomain as a stream of IL and assembling it back using DynamicMethod

Is it possible to pass a lambda expression to a secondary AppDomain as a stream of IL bytes and then assemble it back there using DynamicMethod so it can be called? I'm not too sure this is the right way to go in the first place, so here's the…
aoven
  • 2,248
  • 2
  • 25
  • 36
11
votes
6 answers

Generate dynamic method to set a field of a struct instead of using reflection

Let's say I have the following code which update a field of a struct using reflection. Since the struct instance is copied into the DynamicUpdate method, it needs to be boxed to an object before being passed. struct Person { public int…
Buu
  • 49,745
  • 5
  • 67
  • 85
9
votes
1 answer

Is it possible to invoke internal method from a dynamic method in .NET?

I am trying to invoke an internal method from a dynamically generated one. The il code is simple: ldarg_0, callvirt, ret. Executing the method fails with TypeLoadException saying it cannot load the type on which the internal method is defined. When…
mark
  • 59,016
  • 79
  • 296
  • 580
7
votes
2 answers

Ruby equivalents for PHP's magic methods __call, __get and __set

I am pretty sure that Ruby has these (equivalents for __call, __get and __set), because otherwise how find_by would work in Rails? Maybe someone could give a quick example of how to define methods that act same as find_by? Thanks
spacemonkey
  • 19,664
  • 14
  • 42
  • 62
5
votes
3 answers

Debugging .NET dynamic methods

We are using LINQ very widely in our system. Particularly LINQ-to-objects. So in some places we end up having a LINQ query in memory build up from some huge expressions. The problem comes when there's some bug in the expressions. So we get…
Ihar Bury
  • 485
  • 3
  • 10
4
votes
4 answers

Is this dynamic dispatch?

Is this dynamic dispatch: abstract class A{ public method Meth1(){ //somecode } } class B extends A{ } class C extends A{ } In another class entirely: Some_Method(A a){ a.Meth1(); } I'm not sure if this is dynamic dispatch…
James T
  • 125
  • 1
  • 8
4
votes
2 answers

c# Emitting Dynamic Method Delegate to Load Parametrized Constructor Problem

I am trying create a delegate representation of constructor by emitting a Dynamic Method, which has to match this very "loosely-typed" signature so it can be used with any kind of parametrized constructor: public delegate Object…
4
votes
2 answers

Is there a way to dynamically call a method or set an instance variable in a class in Dart?

I would want to be able to do something like this with a Dart class constructor: class Model { // ... setting instance variables Model(Map fields) { fields.forEach((k,v) => this[k] = v); } } Obviously, this doesn't work, because this…
orion3
  • 9,797
  • 14
  • 67
  • 93
3
votes
4 answers

Ruby create methods from a hash

I have the following code I am using to turn a hash collection into methods on my classes (somewhat like active record). The problem I am having is that my setter is not working. I am still quite new to Ruby and believe I've gotten myself turned…
Jeremy B.
  • 9,168
  • 3
  • 45
  • 57
3
votes
5 answers

Python: using Self and adding methods to an object on the fly

Here's my idea: Start with a simple object: class dynamicObject(object): pass And to be able to add pre written methods to it on the fly: def someMethod(self): pass So that I can do this: someObject =…
Programmin Tool
  • 6,507
  • 11
  • 50
  • 68
3
votes
1 answer

get and set object property using Expression trees instead of Reflection

I would like to dynamically get and set an objects properties as follows: public class Person { public string Name {get; set; } } public class Testing { public void Run() { var p = new Person(); SetValue(p, "Name",…
Langers
  • 141
  • 1
  • 9
3
votes
5 answers

Does Java support dynamic method invocation?

class A { void F() { System.out.println("a"); }} class B extends A { void F() { System.out.println("b"); }} public class X { public static void main(String[] args) { A objA = new B(); objA.F(); } } Here, F() is…
Lazer
  • 90,700
  • 113
  • 281
  • 364
3
votes
1 answer

dynamic method invocation in expression tree

When constructing an expression tree, I have to use nodes invoking external methods in order to obtain values the expression could then continue evaluation with. These methods are supplied as Func and my code has no knowledge of where they…
1
2 3 4