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

Dynamic code compiling and events

P: n/a
Hi all,

Okay, here's something I'd like to do, but I'm not certain its possible.
Thus far in playing with it, I haven't been able to get it going. I'm able
to load and compile a .cs file using the CodeCompiler class. I know that
portion works correctly because I can use the Invoke method of the MethodInfo
object it returns and it triggers my dynamically loaded function. My
problem shows up in +=ing my function onto an event. No matter what I've
tried to give it, I get compiler errors "variable not method", "method name
expected", etc. Is there a way to get this function bound onto my event?
Thanks much!
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
instruo wrote:
Hi all,

Okay, here's something I'd like to do, but I'm not certain its possible.
Thus far in playing with it, I haven't been able to get it going. I'm able
to load and compile a .cs file using the CodeCompiler class. I know that
portion works correctly because I can use the Invoke method of the MethodInfo
object it returns and it triggers my dynamically loaded function. My
problem shows up in +=ing my function onto an event. No matter what I've
tried to give it, I get compiler errors "variable not method", "method name
expected", etc. Is there a way to get this function bound onto my event?
Thanks much!


Have you considered creating a System.Delegate instance?

Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 16 '05 #2

P: n/a
> Have you considered creating a System.Delegate instance?

Frans


I'm not entirely certain what you mean here... naturally I have a delegate
type which my events are based on. Let me explain my setup a bit better:

what I'm doing is implimenting a GUI system using MDX. I have an event
handler delegate and events (MouseDown, Keydown, etc) based on said delegate.
What I'd like to do is be able to += functions compiled from a CodeDom to
said events, effectively giving me a means of scripting my mouse down events
for buttons and the like. My problem is that when I go to do something like
this:

Button.MouseDown += new WidgetEventHandler(...)

I can't find any means of letting it know that its my .GetMethod()'ed
function that I want to use.

I've figured out a work around to this problem, but I'd naturally prefer the
cleaner method of simply binding those function to the events straight up.
Any insight as to how this might be possible, if it is even possible, would
be great. Thanks!
Nov 16 '05 #3

P: n/a
button.GetType().GetEvent("MouseDown").AddHandler( button,
myDynamicMethodDelegate);

Will it do the trick?

HTH,
Alexander Shirshov

"instruo" <in*****@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
Have you considered creating a System.Delegate instance?

Frans


I'm not entirely certain what you mean here... naturally I have a
delegate
type which my events are based on. Let me explain my setup a bit better:

what I'm doing is implimenting a GUI system using MDX. I have an event
handler delegate and events (MouseDown, Keydown, etc) based on said
delegate.
What I'd like to do is be able to += functions compiled from a CodeDom to
said events, effectively giving me a means of scripting my mouse down
events
for buttons and the like. My problem is that when I go to do something
like
this:

Button.MouseDown += new WidgetEventHandler(...)

I can't find any means of letting it know that its my .GetMethod()'ed
function that I want to use.

I've figured out a work around to this problem, but I'd naturally prefer
the
cleaner method of simply binding those function to the events straight up.
Any insight as to how this might be possible, if it is even possible,
would
be great. Thanks!

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.