471,317 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Reflection / Delegate Question

Hi,

I've developed a plug-in application that basically is constructed of 2
pieces 1). the "main framework" 2). channels. Using Reflection in the Main
Framework, i dynamically load Channels. This works fine and great. My
problem is w/ menus. Each Channel returns a Popup Menu (based on an
interface requirement) that gets placed in the Main Framework's main
menubar. Again, works fine. However, what i'm unsure of is the
eventhandler for those specific menu choices. Since the Main Framework only
Hosts the Channel and adds the menu choices to the Main menu bar, when a
user clicks on one of those specific menu items, the Framework does NOT know
what to do with it only the individual Channel will.

Question: If I'm using the wrong approach on this question, please correct
me - how do I dynamically (via Reflection) pass that event firing back to
the Channel? I can't have any hardcoded values in the Framework because I
don't know what each Channel will require. Any sort of example code would
be great if possible or a URL to something.

Thanks in advance,
Doug
Jan 7 '06 #1
4 1396
Doug Handler wrote:
Hi,

I've developed a plug-in application that basically is constructed of 2
pieces 1). the "main framework" 2). channels. Using Reflection in the Main
Framework, i dynamically load Channels. This works fine and great. My
problem is w/ menus. Each Channel returns a Popup Menu (based on an
interface requirement) that gets placed in the Main Framework's main
menubar. Again, works fine. However, what i'm unsure of is the
eventhandler for those specific menu choices. Since the Main Framework only
Hosts the Channel and adds the menu choices to the Main menu bar, when a
user clicks on one of those specific menu items, the Framework does NOT know
what to do with it only the individual Channel will.

Question: If I'm using the wrong approach on this question, please correct
me - how do I dynamically (via Reflection) pass that event firing back to
the Channel? I can't have any hardcoded values in the Framework because I
don't know what each Channel will require. Any sort of example code would
be great if possible or a URL to something.

Thanks in advance,
Doug

I have a similar application. What I do is when I create the context
menus inside my plugins I hook up the events right away to handlers
inside of my plugin. So there is actually no overhead in my hosting
framework.

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
Jan 7 '06 #2
Andreas,

Thanks for the info...I hate to impose, but can you provide me a quick
example so i know exactly what you mean. Right now i'm trying to use
CreateDelegate (via Reflection) and I'm not being very successful <sigh>

d
"Andreas Mueller" <me@privacy.net> wrote in message
news:42*************@individual.net...
Doug Handler wrote:
Hi,

I've developed a plug-in application that basically is constructed of 2
pieces 1). the "main framework" 2). channels. Using Reflection in the
Main Framework, i dynamically load Channels. This works fine and great.
My problem is w/ menus. Each Channel returns a Popup Menu (based on an
interface requirement) that gets placed in the Main Framework's main
menubar. Again, works fine. However, what i'm unsure of is the
eventhandler for those specific menu choices. Since the Main Framework
only Hosts the Channel and adds the menu choices to the Main menu bar,
when a user clicks on one of those specific menu items, the Framework
does NOT know what to do with it only the individual Channel will.

Question: If I'm using the wrong approach on this question, please
correct me - how do I dynamically (via Reflection) pass that event firing
back to the Channel? I can't have any hardcoded values in the Framework
because I don't know what each Channel will require. Any sort of example
code would be great if possible or a URL to something.

Thanks in advance,
Doug

I have a similar application. What I do is when I create the context menus
inside my plugins I hook up the events right away to handlers inside of my
plugin. So there is actually no overhead in my hosting framework.

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net

Jan 7 '06 #3
Doug Handler wrote:
Andreas,

Thanks for the info...I hate to impose, but can you provide me a quick
example so i know exactly what you mean. Right now i'm trying to use
CreateDelegate (via Reflection) and I'm not being very successful <sigh>

d
"Andreas Mueller" <me@privacy.net> wrote in message
news:42*************@individual.net...
Doug Handler wrote:
Hi,

I've developed a plug-in application that basically is constructed of 2
pieces 1). the "main framework" 2). channels. Using Reflection in the
Main Framework, i dynamically load Channels. This works fine and great.
My problem is w/ menus. Each Channel returns a Popup Menu (based on an
interface requirement) that gets placed in the Main Framework's main
menubar. Again, works fine. However, what i'm unsure of is the
eventhandler for those specific menu choices. Since the Main Framework
only Hosts the Channel and adds the menu choices to the Main menu bar,
when a user clicks on one of those specific menu items, the Framework
does NOT know what to do with it only the individual Channel will.

Question: If I'm using the wrong approach on this question, please
correct me - how do I dynamically (via Reflection) pass that event firing
back to the Channel? I can't have any hardcoded values in the Framework
because I don't know what each Channel will require. Any sort of example
code would be great if possible or a URL to something.

Thanks in advance,
Doug


I have a similar application. What I do is when I create the context menus
inside my plugins I hook up the events right away to handlers inside of my
plugin. So there is actually no overhead in my hosting framework.

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net


Here is a extremely simplified version of what I do:

using System;
using System.Windows.Forms;

namespace ConsoleApplication13
{
public interface PlugIn
{
Menu Menu(object context);
}

class PlugInImp : PlugIn
{
Menu PlugIn.Menu(object context)
{
ContextMenu mnu = new ContextMenu();
mnu.MenuItems.Add("My Menu Item", new
EventHandler(OnMyMnuClick));

return mnu;
}
private void OnMyMnuClick(object sender, EventArgs e)
{
// do click stuff
}
}

public static class HostFramework
{
public static void RegisterPlugIn(PlugIn pl)
{
Menu mnu = pl.Menu(null);
HookUpMenu(mnu);
}
private static void HookUpMenu(Menu mnu)
{
// ...
}
}
class Program
{
static void Main(string[] args)
{
// in the real world, this happens inside of a
// plugin init code
HostFramework.RegisterPlugIn(new PlugInImp());
}
}
}

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
Jan 7 '06 #4
Ok, on the same page....cool, thank you. I PM'd you, prior, so disregard.

dh
"Andreas Mueller" <me@privacy.net> wrote in message
news:42*************@individual.net...
Doug Handler wrote:
Andreas,

Thanks for the info...I hate to impose, but can you provide me a quick
example so i know exactly what you mean. Right now i'm trying to use
CreateDelegate (via Reflection) and I'm not being very successful <sigh>

d
"Andreas Mueller" <me@privacy.net> wrote in message
news:42*************@individual.net...
Doug Handler wrote:

Hi,

I've developed a plug-in application that basically is constructed of 2
pieces 1). the "main framework" 2). channels. Using Reflection in the
Main Framework, i dynamically load Channels. This works fine and great.
My problem is w/ menus. Each Channel returns a Popup Menu (based on an
interface requirement) that gets placed in the Main Framework's main
menubar. Again, works fine. However, what i'm unsure of is the
eventhandler for those specific menu choices. Since the Main Framework
only Hosts the Channel and adds the menu choices to the Main menu bar,
when a user clicks on one of those specific menu items, the Framework
does NOT know what to do with it only the individual Channel will.

Question: If I'm using the wrong approach on this question, please
correct me - how do I dynamically (via Reflection) pass that event
firing back to the Channel? I can't have any hardcoded values in the
Framework because I don't know what each Channel will require. Any sort
of example code would be great if possible or a URL to something.

Thanks in advance,
Doug

I have a similar application. What I do is when I create the context
menus inside my plugins I hook up the events right away to handlers
inside of my plugin. So there is actually no overhead in my hosting
framework.

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net


Here is a extremely simplified version of what I do:

using System;
using System.Windows.Forms;

namespace ConsoleApplication13
{
public interface PlugIn
{
Menu Menu(object context);
}

class PlugInImp : PlugIn
{
Menu PlugIn.Menu(object context)
{
ContextMenu mnu = new ContextMenu();
mnu.MenuItems.Add("My Menu Item", new
EventHandler(OnMyMnuClick));

return mnu;
}
private void OnMyMnuClick(object sender, EventArgs e)
{
// do click stuff
}
}

public static class HostFramework
{
public static void RegisterPlugIn(PlugIn pl)
{
Menu mnu = pl.Menu(null);
HookUpMenu(mnu);
}
private static void HookUpMenu(Menu mnu)
{
// ...
}
}
class Program
{
static void Main(string[] args)
{
// in the real world, this happens inside of a
// plugin init code
HostFramework.RegisterPlugIn(new PlugInImp());
}
}
}

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net

Jan 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by BK | last post: by
3 posts views Thread by timothy | last post: by
2 posts views Thread by Luis Arvayo | last post: by
2 posts views Thread by mswlogo | last post: by
10 posts views Thread by Ron | last post: by
5 posts views Thread by Klaudiusz Bryja | last post: by
reply views Thread by rosydwin | last post: by

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.