473,484 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

writing event handlers with argument types defined in reflected dll's possible ?

Suppose I have object O with an event E that are
defined in an assembly M that I am referencing in
my code via reflection. M also defines object A which
is an argument to E.

At compile-time, how can I write a function that meets
the signature for event E, when the compiler
doesn't know about A ?

I can solve this problem using Delegate.CreateDelegate
etc if the type of E's arguments are known at
compile time, but what about when there is an
unknown type ?

TIA,
Stephen
Nov 16 '05 #1
3 1546

Użytkownik "Stephen Ahn" <noaddress> napisał w wiadomo¶ci
news:OW**************@tk2msftngp13.phx.gbl...
Suppose I have object O with an event E that are
defined in an assembly M that I am referencing in
my code via reflection. M also defines object A which
is an argument to E.

At compile-time, how can I write a function that meets
the signature for event E, when the compiler
doesn't know about A ?

I can solve this problem using Delegate.CreateDelegate
etc if the type of E's arguments are known at
compile time, but what about when there is an
unknown type ?


You could read the E's signature at run-time, create a handler code
dynamically (as string), compile it to memory (adding a reference to M) and
create a delegate handler from compiled method.

But since you do not know anything about the delegate's argument type, how
would you like to make use of it?

regards,
Wiktor Zychla
Nov 16 '05 #2
"Wiktor Zychla" <us**@nospam.com.eu> wrote in message
news:OY*************@tk2msftngp13.phx.gbl...
You could read the E's signature at run-time, create a handler code
dynamically (as string), compile it to memory (adding a reference to M)
and create a delegate handler from compiled method.

But since you do not know anything about the delegate's argument type, how
would you like to make use of it?


Thanks for your response.

Well, the argument type is a simple class with just a few public properties.
The types of the properties are standard dotnet types.
Since we know the names of the properties, I was thinking
they could be referenced via reflection.

We had to use reflection to access the third party dll, because it
is not signed, and not in the GAC. The dlls are also not in a
subdirectory of our app.

Maybe we are approaching this the wrong way (?)

Stephen.
Nov 16 '05 #3
Stephen,

Did you try to create a function with generic parameters? i.e.

void GenericHandler(object sender, EventArgs e)
{...}

typeof(O).GetEvent("E").AddHandler(o, new EventHandler(GenericHandler));
Alexander

"Stephen Ahn" <noaddress> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
Suppose I have object O with an event E that are
defined in an assembly M that I am referencing in
my code via reflection. M also defines object A which
is an argument to E.

At compile-time, how can I write a function that meets
the signature for event E, when the compiler
doesn't know about A ?

I can solve this problem using Delegate.CreateDelegate
etc if the type of E's arguments are known at
compile time, but what about when there is an
unknown type ?

TIA,
Stephen

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3555
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
4
4527
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
9
5716
by: VK | last post by:
My original idea of two trains, however pictural it was, appeared to be wrong. The truth seems to be even more chaotic. IE implements its standard down-up model: any mouse event goes from the...
9
14414
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
4
9668
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
2
1651
by: 6tc1 | last post by:
Hi all, I'm inquiring about the mechanism that is used to implement event handlers in .NET (not really relevant, but I'm using C#). Anyway, I've noticed that I can pass an object in an event...
4
3240
by: Jonathan Wood | last post by:
I'm building a Web application but this question should be common to all C# applications. When I use a class, and I want to add event handlers or override base class methods, how do I know the...
1
1474
by: VAXman- | last post by:
I have code which is created from a content mamagement system. It places some handlers on tags with in-line registration: <tag... onmousedown="mousedownHandler(this);" ...> I want to...
2
5086
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
7079
marktang
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,...
0
7137
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5403
agi2029
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,...
1
4838
isladogs
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...
0
4527
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...
0
3044
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
587
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
234
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.