Last active
December 20, 2015 16:49
-
-
Save yemrekeskin/6164643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public delegate void StatusChangeEventHandler(MessageStatus newStatus); | |
| public enum MessageStatus { Approved , InApproval , Executed } | |
| public class Message | |
| { | |
| private MessageStatus messageStatus; | |
| public MessageStatus MessageStatus | |
| { | |
| get { return messageStatus; } | |
| set | |
| { | |
| messageStatus = value; | |
| Notify(); | |
| } | |
| } | |
| private void Notify() | |
| { | |
| if (_OnStatusChange != null) | |
| _OnStatusChange(messageStatus); | |
| } | |
| private event StatusChangeEventHandler _OnStatusChange; | |
| public event StatusChangeEventHandler OnStatusChange | |
| { | |
| add | |
| { | |
| _OnStatusChange += value; // to Subscribe | |
| } | |
| remove | |
| { | |
| _OnStatusChange -= value; // to UnSubscribe | |
| } | |
| } | |
| } | |
| // using | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Message msg = new Message(); | |
| msg.MessageStatus = MessageStatus.InApproval; | |
| msg.OnStatusChange += msg_OnStatusChange; // Subscribe it | |
| msg.MessageStatus = MessageStatus.InApproval; | |
| msg.OnStatusChange += msg_OnStatusChange1; // Subscribe it | |
| msg.MessageStatus = MessageStatus.Approved; | |
| msg.MessageStatus = MessageStatus.Executed; | |
| msg.OnStatusChange += msg_OnStatusChange2; | |
| msg.OnStatusChange -= msg_OnStatusChange1; // UnSubscribe -msg_OnStatusChange1 | |
| Console.WriteLine(); | |
| msg.MessageStatus = MessageStatus.InApproval; | |
| Console.ReadLine(); | |
| } | |
| static void msg_OnStatusChange(MessageStatus newStatus) | |
| { | |
| Console.WriteLine("Status -{0} ", newStatus); | |
| } | |
| static void msg_OnStatusChange1(MessageStatus newStatus) | |
| { | |
| Console.WriteLine("Status -{0} ", newStatus); | |
| } | |
| static void msg_OnStatusChange2(MessageStatus newStatus) | |
| { | |
| Console.WriteLine("Status -{0} ", newStatus); | |
| } | |
| static void msg_OnStatusChange3(MessageStatus newStatus) | |
| { | |
| Console.WriteLine("Status -{0} ", newStatus); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment