dynamic-method

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 NullReferenceException and the stack trace leads us nowhere (to [Lightweight Function]). The except...

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 id; } class Test { static void Main() { object person = RuntimeHelpers.GetObject...

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 (detailed) reason I ask this question... In my applications, there are a lot of cases when I ...

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

Dear ladies and sirs. 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 I think of it, this seems logical, because the dynamic method hos...

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 ParamsConstructorDelegate(params object[] parameters); and the code for this creating the delegate looks li...

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 being invoked dynamically, isn't it? This article says: ... the Java bytecode doesn’t ...

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

Hi, 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 ...

Defining methods on the fly in Ruby / Rails - how to set params?

I am trying to define a set of functions where I can pass in given params. for example, how do i do the following? >> get_1_type("xxx") V4_RELATIONSHIP_TYPES=[1=>2,3=>4] V4_RELATIONSHIP_TYPES.keys.each do |key| self.class.send(:define_method, "get_#{key}_type".downcase) do return GuidInfo.get_or_new(PARAMS, V4_RELATIONSHIP_TYPES[...

I know how to set class methods, but how do I set instance methods on the fly?

I asked a previous question on class methods, but I really want to understand how to do this for instance methods as well. Thanks! =) The code below sets class methods for a given array: class Testing V4_RELATIONSHIP_TYPES=[1=>2,3=>4] V4_RELATIONSHIP_TYPES.keys.each do |key| self.class.send(:define_method, "get_#{key}_type"...

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 = dyncamicObject() someObject._someMethod = someMethod someObject._someMethod() Problem is, it wants me to specify the self...