Reflection / Delegate Question

D

Doug Handler

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
 
A

Andreas Mueller

Doug said:
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
 
D

Doug Handler

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
 
A

Andreas Mueller

Doug said:
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
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
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
 
D

Doug Handler

Ok, on the same page....cool, thank you. I PM'd you, prior, so disregard.

dh
Andreas Mueller said:
Doug said:
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
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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top