ilgenerator

Call a method when a generic event occurs

若如初见. 提交于 2020-01-07 01:51:59
问题 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 keep getting an exception when the method to call is an instance one, not static. Here is my partial code: public class Operation { public bool EventFired { get { return _eventFired; } } private bool _eventFired = false; public void Execute(object

Call a method when a generic event occurs

自闭症网瘾萝莉.ら 提交于 2020-01-07 01:51:17
问题 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 keep getting an exception when the method to call is an instance one, not static. Here is my partial code: public class Operation { public bool EventFired { get { return _eventFired; } } private bool _eventFired = false; public void Execute(object

ILGenerator call instance method with parameter

不想你离开。 提交于 2019-12-23 03:18:23
问题 I am trying to construct an instance of a generic type and call a method on that instance. Then return the result of the method. MethodInfo methodInfo = ...; ... var genericType = typeof(GenericType<>).MakeGenericType(typeof(TOutput)); il.Emit(OpCodes.Newobj, genericType.GetConstructor(Type.EmptyTypes)); il.Emit(OpCodes.Ldobj, methodInfo); il.Emit(OpCodes.Callvirt, genericeClientHelper.GetMethod("MethodName", new Type[] { typeof(MethodInfo) })); il.Emit(OpCodes.Ret); I keep getting a 'System

ILGenerator: How to use unmanaged pointers? (I get a VerificationException)

↘锁芯ラ 提交于 2019-12-21 16:25:45
问题 I'm making a sound synthesis program in wich the user can create his own sounds doing node-base compositing, creating oscillators, filters, etc... The program compiles the nodes onto an intermediary language wich is then converted onto an MSIL via the ILGenerator and DynamicMethod It works with an array in wich all operations and data are stored, but it will be faster if i was able to use pointers to allow me to do some bit-level operations later PD: Speed is very important!! I noticed that

generics with IL?

淺唱寂寞╮ 提交于 2019-12-21 05:01:26
问题 Is it possible to use generics with the IL Generator? DynamicMethod method = new DynamicMethod( "GetStuff", typeof(int), new Type[] { typeof(object) }); ILGenerator il = method.GetILGenerator(); ... etc 回答1: Yes, it is possible, but not with the DynamicMethod class. If you are restricted to using this class, you're out of luck. If you can instead use a MethodBuilder object, read on. Emitting the body of a generic method is, for most intents and purposes, no different from emitting the body of

Are there any gotchas or good reasons not to use autosproc for stored procedure calls?

孤者浪人 提交于 2019-12-11 06:14:38
问题 I've implemented a data access layer that populates generic entities from a datareader using a variation of the third monkey approach (http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx). This works well, performs well and saves me writing loads of repetetive code for data retrieval. Now I want to add methods that take a generic entity and convert it to a parameter list for feeding to a stored proc so that I can add data persistence to my monkey's trick collection. I found

Redirecting to a dynamic method from a generic event handler

末鹿安然 提交于 2019-12-11 05:29:15
问题 I'm trying to write a class that's to be used to trigger a call to a method from an arbitrary event but I'm stuck as I simply cannot figure out a way to reference 'this' from emitted MSIL code. This example should describe what I'm looking for: class MyEventTriggeringClass { private object _parameter; public void Attach(object source, string eventName, object parameter) { _parameter = parameter; var e = source.GetType().GetEvent(eventName); if (e == null) return; hookupDelegate(source, e); }

transferring one object properties values to another one

时光毁灭记忆、已成空白 提交于 2019-12-05 02:04:05
问题 Before all, I know about AutoMapper , and I don't want to use it. Because I'm learning C# and I want to receive a deep view of it. So I'm trying to do this issue (explained below) myself. However, I'm trying to create a property copier to cope values of one type's properties to another one, if the property has the same name and type and is readable from source and writable in target. I'm using type.GetProperties() method. Sampled method is here: static void Transfer(object source, object

Is there a good wrapper around ILGenerator? [closed]

本秂侑毒 提交于 2019-12-04 11:31:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm using System.Reflection.Emit for a while now, and find it (who don't?) as painful as bug prone. Do you know if there is a good

transferring one object properties values to another one

我怕爱的太早我们不能终老 提交于 2019-12-03 16:35:47
Before all, I know about AutoMapper , and I don't want to use it. Because I'm learning C# and I want to receive a deep view of it. So I'm trying to do this issue (explained below) myself. However, I'm trying to create a property copier to cope values of one type's properties to another one, if the property has the same name and type and is readable from source and writable in target. I'm using type.GetProperties() method. Sampled method is here: static void Transfer(object source, object target) { var sourceType = source.GetType(); var targetType = target.GetType(); var sourceProps =