Passing Event Args :(

Topics: CAB & Smart Client Software Factory
Oct 11, 2005 at 11:06 AM
originally posted by: markgmarkg

I was trying to pass some info via EventArgs to a command handler and nothing happened.

After short investigation I found this method in EventCommandAdapter class:

public void InvokerEventHandler(object sender, EventArgs e)

And FireCommand() implementation in the CommandAdapter class looks as following:

if (ExecuteCommand != null)
ExecuteCommand(this, EventArgs.Empty);

I'm wondering what was the design consideration to pass no EventArgs?
Oct 12, 2005 at 4:25 AM
originally posted by: DLorenz

Did you pass data with EventArgs? Or DataEventArgs?
Oct 12, 2005 at 4:58 AM
originally posted by: markgmarkg

Actually, I defined CommandHandler attribute and tried to retrieve some info from the EventArgs obect and got nothing.

By the way, does it matter which event args type is in use? In my case, the signature looks like:

public void DoIt( object sender, EventArgs e )
Oct 12, 2005 at 7:05 AM
originally posted by: DLorenz

Why don't you use EventPublisher/EventSubscibers instead? Then you can use DataEventArgs and pass the data that way.
Oct 12, 2005 at 7:15 AM
originally posted by: markgmarkg

I'm sure that there are various solutions for this specific problem, but I'm still wondering what were the design considerations for this specific code.

Why does EventArgs get empty by design on command handler invocation?
Oct 12, 2005 at 7:50 AM
originally posted by: jcelich

The CommandAdapter just provides a default virtual implementation of FireCommand. The idea is that everyone should create the adapters that best suits their needs. The way EventArgs are processed and passed to the command must be implemented in these command adapters.

This default implementation just provides command notification and not assumes anything about how to process the invoker's event args, and it is aligned with the command Execute method in which you cannot provide event args.

So, for your case, you just need to create your own command adapter and optionally register it with the ICommandAdapterMapService.