Created
March 24, 2018 13:42
-
-
Save lai32290/84eb39905c9acc9b104b75b3ee9b94ea to your computer and use it in GitHub Desktop.
Observer Class
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 class Observer<T> | |
{ | |
public Observer() { } | |
public Observer(T initValue) | |
{ | |
value = initValue; | |
} | |
private T value; | |
public T Value | |
{ | |
get | |
{ | |
return value; | |
} | |
set | |
{ | |
this.value = value; | |
if(OnChange != null) | |
{ | |
OnChange(this.value); | |
} | |
} | |
} | |
private event ChangeValue OnChange; | |
public delegate void ChangeValue(T value); | |
public void Subscribe(ChangeValue subscribe) | |
{ | |
OnChange += subscribe; | |
} | |
public void Unsubscribe(ChangeValue subscribe) | |
{ | |
OnChange -= subscribe; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment