By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.