Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created January 17, 2015 20:53
Show Gist options
  • Save scionwest/c670b6ef1415c121ca4e to your computer and use it in GitHub Desktop.
Save scionwest/c670b6ef1415c121ca4e to your computer and use it in GitHub Desktop.
public abstract class ChatMessage : MessageBase<string>
{
/// <summary>
/// Initializes a new instance of the <see cref="ChatMessage"/> class.
/// </summary>
/// <param name="message">The message.</param>
public ChatMessage(string message)
{
this.Message = message;
}
/// <summary>
/// Gets the message.
/// </summary>
public string Message { get; private set; }
}
public class WhisperMessage : ChatMessage
{
/// <summary>
/// Initializes a new instance of the <see cref="WhisperMessage"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="target">The target.</param>
public WhisperMessage(string message, ICharacter target) : base(message)
{
this.Target = target;
}
/// <summary>
/// Gets the target that this message is intended for.
/// </summary>
public ICharacter Target { get; private set; }
public override string GetContent()
{
return base.GetContent<string>();
}
}
### Usage
public void Test()
{
var notification = new NotificationManager();
var handler = new ChatMessageHandler<WhisperMessage>();
handler.Register((msg, sub) =>
{
if (string.IsNullOrEmpty(msg.Content))
{
sub.Unsubscribe(notification);
}
}, null);
notification.Subscribe<WhisperMessage>(handler);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment