Last active
June 22, 2017 11:54
-
-
Save danhab99/1bfebab758565df72297d99108addc7a to your computer and use it in GitHub Desktop.
This object and it's interface can be used to catch the accessors in an object
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ObjDB | |
{ | |
public interface IEventedType<T> | |
{ | |
T Value { get; set; } | |
event EventHandler<T> OnSet; | |
event EventHandler<T> OnGet; | |
} | |
public class EventedType<T> : IEventedType<T> | |
{ | |
private T _value; | |
public T Value { | |
get | |
{ | |
var temp = value; | |
OnGet?.Invoke(this, temp); | |
return temp; | |
} | |
set | |
{ | |
var temp = value; | |
_value = temp; | |
OnSet?.Invoke(this, temp); | |
} | |
} | |
public EventedType() | |
{ | |
} | |
public EventedType(T obj) | |
{ | |
Value = obj; | |
} | |
public static implicit operator T(EventedType<T> o) => o.Value; | |
public static explicit operator EventedType<T>(T o) => new EventedType<T>(o); | |
public event EventHandler<T> OnSet; | |
public event EventHandler<T> OnGet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So its like... a regular Property, which is not INotifyPropertyChanged compatible?
isn't a snippet like ...
... better?
Please feel free to tell me about the benefits. I might be too stupid to see them right away
The only benefit i see, is that you can have multiple subscribers...?