Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd
like to generate the code that the delegates describe. Do anyone have an
easy way to do this?
cheers,
mortb 5 1517
Hi,
What do you mean by "generate the code that the delegates describe"?
--
Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message
news:eX******** ******@TK2MSFTN GP02.phx.gbl...
Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd
like to generate the code that the delegates describe. Do anyone have an
easy way to do this?
cheers,
mortb
I'll try to explain by an example:
I declare a and assign delegate variable:
MyDelType myDel = delgate() { doSomeStuff(); };
myDel += delegate() { doSomeOtherStuf f(); };
What I would like to do is to have a method:
string generateCodeFro mDel(MyDelType theDel)
....that will return something like a string containing the "program":
"doSomeStuf f();
doSomeOtherStuf f();"
cheers,
mortb
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:eC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,
What do you mean by "generate the code that the delegates describe"?
--
Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message
news:eX******** ******@TK2MSFTN GP02.phx.gbl...
>Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd like to generate the code that the delegates describe. Do anyone have an easy way to do this?
cheers, mortb
Hi,
I don't think there's an easy way to get C# code out of an anonymous method
at runtime.
First of all, you'd call GetInvocationLi st to get a list of all of the
delegates.
Secondly, on each Delegate in the list you'd call GetMethodBody on the
Method property.
The problem here is that the MethodBody class only gives you the ability to
get the IL as a byte[], and there is no easy way to convert that to C#,
AFAIK.
--
Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message
news:uA******** *****@TK2MSFTNG P03.phx.gbl...
I'll try to explain by an example:
I declare a and assign delegate variable:
MyDelType myDel = delgate() { doSomeStuff(); };
myDel += delegate() { doSomeOtherStuf f(); };
What I would like to do is to have a method:
string generateCodeFro mDel(MyDelType theDel)
...that will return something like a string containing the "program":
"doSomeStuf f();
doSomeOtherStuf f();"
cheers,
mortb
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:eC******** ******@TK2MSFTN GP04.phx.gbl...
>Hi,
What do you mean by "generate the code that the delegates describe"?
-- Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message news:eX******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd like to generate the code that the delegates describe. Do anyone have an easy way to do this?
cheers, mortb
Thats not quite how delegates work. The delegate is like a list of functions
to call so adding one to a delegate like += doesnt append the source of the
new function to the source of the other, it adds it to the list. What you
would need to do would be to use the CodeDom to try and reverse engineer the
code of each one individually in a loop. You wont necesarily be able to get
the same code back and it may not compile due to the function duplicate
variable names etc.
Why would you need such a function as it will take a long while to write and
I cant see big benefit of automating it?
Ciaran O'Donnell
"mortb" wrote:
I'll try to explain by an example:
I declare a and assign delegate variable:
MyDelType myDel = delgate() { doSomeStuff(); };
myDel += delegate() { doSomeOtherStuf f(); };
What I would like to do is to have a method:
string generateCodeFro mDel(MyDelType theDel)
....that will return something like a string containing the "program":
"doSomeStuf f();
doSomeOtherStuf f();"
cheers,
mortb
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:eC******** ******@TK2MSFTN GP04.phx.gbl...
Hi,
What do you mean by "generate the code that the delegates describe"?
--
Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message
news:eX******** ******@TK2MSFTN GP02.phx.gbl...
Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd
like to generate the code that the delegates describe. Do anyone have an
easy way to do this?
cheers,
mortb
Hi,
And BTW the GetMethodBody method is new to the 2.0 framework. In earlier
framework versions you'd have to go Interop, I believe.
--
Dave Sexton
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:ut******** ******@TK2MSFTN GP03.phx.gbl...
Hi,
I don't think there's an easy way to get C# code out of an anonymous
method at runtime.
First of all, you'd call GetInvocationLi st to get a list of all of the
delegates.
Secondly, on each Delegate in the list you'd call GetMethodBody on the
Method property.
The problem here is that the MethodBody class only gives you the ability
to get the IL as a byte[], and there is no easy way to convert that to C#,
AFAIK.
--
Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message
news:uA******** *****@TK2MSFTNG P03.phx.gbl...
>I'll try to explain by an example:
I declare a and assign delegate variable:
MyDelType myDel = delgate() { doSomeStuff(); }; myDel += delegate() { doSomeOtherStuf f(); };
What I would like to do is to have a method:
string generateCodeFro mDel(MyDelType theDel)
...that will return something like a string containing the "program":
"doSomeStuff() ; doSomeOtherStu ff();"
cheers, mortb
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:eC******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Hi,
What do you mean by "generate the code that the delegates describe"?
-- Dave Sexton
"mortb" <mo***@nospam.n ospamwrote in message news:eX****** ********@TK2MSF TNGP02.phx.gbl. .. Hello!
I make use of anonymous delegates in my code. For debugging purposes I'd like to generate the code that the delegates describe. Do anyone have an easy way to do this?
cheers, mortb This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application to create certain textboxes, labels,
and combo boxes? Any ideas would be appreciated.
Thanks
|
by: Michael Rockwell |
last post by:
I am new to using C# generics and I am liking what I am finding. However the
examples in online help are lacking. Can someone help me with the FindAll
method of the generic List class? As I understand the method, it will return
a list that meets the criteria evaluated in the delegate function that I use
for evaluation. I am not sure how to write this delegate, how do I get the
list item to evaluate in my delegate. Is their a defined...
|
by: Jeff Louie |
last post by:
Well I wonder if my old brain can handle threading. Dose this code look
reasonable.
Regards,
Jeff
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
|
by: john |
last post by:
Hi,All MS Tech Gurus:
I need your help!!! It is the second time I post this message, I need get
some feedback ASAP, Please Help!!
Thanks a lot in advance.
John
I have a csharp method, using emit to dynamically generate classes & method
depends on the meta table in the database,here is my situation
1) In One method I generated the code Dynamic IL Code (Depends on the data
pass to it), The generated code works for one dataset but does...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
| |
by: sajin |
last post by:
Hi All..
We are using VB .Net 2005 for implementing an API. API needs to
generate events. For this client wants us to use Windows Callback
(delegate implementation). The intention of using Windows Callback is
to generalise our API so that it can be compatible with any other
language e.g. C++.
Using normal delegates will not help us since delegates is a VB.Net
feature and any other language cant make a use of it. Could please
|
by: Niels Ull |
last post by:
Hi!
I'm using .Net 2.0 and C#, and I'm trying to generate code for build time
AOP. But I cannot find out how to generate an anonymous delegate.
E.g. generating code like this:
class MyClassWrapper
{
|
by: Simon Woods |
last post by:
Hi
I'm trying to generate a simple evaluator-type app.
I want to generate a list of operators and say how each is to be evaluated.
So, e.g., I want to add to a list of operators
Operators.Add "+", evaluation function here
|
by: hcaptech |
last post by:
This is my Test.can you help me ?
1.Which of the following statement about C# varialble is incorrect ?
A.A variable is a computer memory location identified by a unique name
B.A variable's name is used to access and read the value stored in it
C.A variable is allocated or deallocated in memory during runtime
D.A variable can be initialized at the time of its creation or later
2. The.……types feature facilitates the definition of classes...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |