Skip to content

Instantly share code, notes, and snippets.

@Redth
Created June 7, 2014 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Redth/a7442c6b437835b4b97d to your computer and use it in GitHub Desktop.
Save Redth/a7442c6b437835b4b97d to your computer and use it in GitHub Desktop.
public class MsgHub
{
public static MsgHub Instance = new MsgHub();
public static void Send<TArgs> (TArgs args)
{
var msg = args.GetType ().Name;
MessagingCenter.Send<MsgHub, TArgs> (Instance, msg, args);
}
public static void Subscribe<TArgs> (object subscriber, Action<TArgs> callback)
{
var msg = typeof(TArgs).Name;
MessagingCenter.Subscribe<MsgHub, TArgs> (subscriber, msg, (s, a) => callback(a), Instance);
}
public static void Unsubscribe<TArgs> (object subscriber)
{
var msg = typeof(TArgs).Name;
MessagingCenter.Unsubscribe<MsgHub, TArgs> (subscriber, msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment