Skip to content

Instantly share code, notes, and snippets.

@jakehawken
Last active June 25, 2019 16:23
Show Gist options
  • Select an option

  • Save jakehawken/03aebd639b065f1a0ff19e334259345f to your computer and use it in GitHub Desktop.

Select an option

Save jakehawken/03aebd639b065f1a0ff19e334259345f to your computer and use it in GitHub Desktop.
Getting that sweet, sweet `didSet` functionality in C#.
using System;
using System.Collections;
using System.Collections.Generic;
public class PropertyBox<T>
{
private T value;
public Action<T> didSet;
public Action<T,T> willSet;
public T get() {
return value;
}
public static PropertyBox<Q> withValue<Q>(Q val) {
return new PropertyBox<Q>() { value = val };
}
public void set(T val) {
if (willSet != null) {
willSet(value, val);
}
value = val;
if (didSet != null) {
didSet(val);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment