How to ... ?

Topics: Mobile Client Software Factory
Oct 17, 2006 at 6:55 AM
originally posted by: kosov

Hi all,

I am currently testing the MCSF and I have a question.

Is there a solution to call a method with parameters in a module A from a module B without referencing the Module A in module B ?

In the SCSF I will make my own EventArgs with an arraylist inside but with the MCSF it is impossible because the EventBroker takes only EventArgs.

Any idea ?
Oct 17, 2006 at 2:37 PM
originally posted by: AdamB_

Hi... not sure if this helps, but if all you want to do is pass more a more complex object than EventArgs, you can actually use the DataEventArgs<T> object instead...

Here's a simple example using EventPublication and EventSubscription to illustrate... note that DataEventArgs inherits from EventArgs... and we can just cast the "EventArgs" back to DataEventArgs<DateTime> at the other end.

public class Class1
EventPublication("topic://DoStuff", PublicationScope.Global)
public event EventHandler DoStuff;

public void CallTheEvent
if (this.DoStuff != null)
this.DoStuff(this, (EventArgs)(new DataEventArgs<DateTime>(lastSync)));

public class Class2

public void OnDoStuff(object sender, EventArgs e)
DateTime lastSync = (DateTime)((DataEventArgs<DateTime>)e).Data;
Oct 17, 2006 at 7:34 PM
originally posted by: dcazzulino

This is not entirely correct.
The event signature cannot expose anything other than EventArgs, but when you fire the event, you can pass a derived class, that you later on downcast from the subscriber.

This is a known limitation of CAB mobile based on a limitation on the .NET CF and its support for delegates.
Oct 17, 2006 at 7:41 PM
originally posted by: AdamB_

Indeed :)

Thanks for clarifying that point! I must admit I myself fell prey to that one early on.

Note: my above code works just fine, and agrees with my learned friend's post.
Oct 18, 2006 at 12:24 AM
originally posted by: Aleks_DP

Thx Adam.

Just another detail for those who will read this thread, the DataEventArgs is here : using Microsoft.Practices.Mobile.CompositeUI.Utility;