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
2
votes
3 answers

Javascript: How to build a method dynamically from string data?

I have an XML document that defines a task, which is a list of actions to be performed on certain data. I need to convert this "task list" to a Javascript method which can be called at some later time, which in turn calls a series of pre-defined…
Brian Lacy
  • 18,785
  • 10
  • 55
  • 73
2
votes
2 answers

Comparing all properties of an object using expression trees

I'm trying to write a simple generator that uses an expression tree to dynamically generate a method that compares all properties of an instance of a type to the properties of another instance of that type. This works fine for most properties, like…
stringargs
  • 95
  • 1
  • 5
2
votes
2 answers

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] …
meow
  • 27,476
  • 33
  • 116
  • 177
2
votes
1 answer

What's the simplest way of adding state to CLR's DynamicMethod?

I'm doing a little code generation with DynamicMethod and I have a problem that would be handily solved by adding a little state, like a field. Unfortunately, I can't push this state into one of the method's parameters, so I basically need to close…
naasking
  • 2,514
  • 1
  • 27
  • 32
2
votes
2 answers

Emit IL OpCodes from C# source code

How to parse C# source code for generating IL opcodes, that could be used in DynamicMethod? I want to execute code dynamically without generating unnecessary assemblies. Something like this: var body = "return \"sample\";"; var dm = new…
lorond
  • 3,856
  • 2
  • 37
  • 52
1
vote
2 answers

Missing static get method on Grails Domain Class

We keep getting the following error intermittently in production with grails. It says there is no get method for the given domain class. This happens once every few days on code that is executing about 300 times/minute. We haven't been able to…
Matt Campbell
  • 687
  • 1
  • 7
  • 17
1
vote
2 answers

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,…
meow
  • 27,476
  • 33
  • 116
  • 177
1
vote
1 answer

How invoke Instance Method from singleton with emit

I have exception: Operation could destabilize the runtime , and i dont know why :(. Please Help me. I Added Local, but still not working... Method want to create dynamically (REF000001): public static int REF000001(int REF000002, object REF000003,…
1
vote
1 answer

Accessing a property or method by passing string to a function

I have a .net assembly providing a huge number of API's and I need to write a COM wrapper for it . I can not write interfaces to each and every method and property provided my the .net assembly due to time constraints. Instead What i plan to do is…
Sanju
  • 1,974
  • 1
  • 18
  • 33
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

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
2 answers

How does one look up documentation for dynamic methods and or dynamic objects in Grails?

I'm familiar with the concept that dynamic methods are added via AOP to domain objects in Grails. But since they're dynamic, how is it that you find the documentation to them? It wouldn't be obvious where to look for the documentation for these…
leeand00
  • 25,510
  • 39
  • 140
  • 297
0
votes
1 answer

Ruby send method with rails associations

I have been messing about with making a sortable table module thing. I know some might exist but want to get experience doing this myself. I had the idea of have it like so: SortedTable.new(ModelName, Hash_Of_Columns_And_Fields,…
RailsSon
  • 19,897
  • 31
  • 82
  • 105