public void Dispose() { if (Interlocked.Exchange(ref _observer, null) == null) { return; } _binding.ResultChanged -= OnBindingResultChanged; _binding.Unbind(); _binding = null; }
public Subscription( IObserver <BindingResultChange <TResult> > observer, IRootBindingPrototype <TGraph, TResult> prototype, TGraph graph) { _observer = observer; _binding = prototype.Clone(); _binding.ResultChanged += OnBindingResultChanged; _binding.Bind(graph); }
private static void Main() { var person = new Person(); // We can create a prototype root binding from the expression: IRootBindingPrototype <Person, bool> prototype = Binding.CreatePrototype((Person x) => x.Name == null | x.Name.First.Length <= 3); // From the prototype, we can clone new instances of the root binding: IRootBinding <Person, bool> binding = prototype.Clone(); // The root binding provides a very simple API: binding.ResultChanged += (object _, BindingResultChange <bool> e) => Console.WriteLine(e); binding.Bind(person); person.Name = new Name("1234"); // True person.Name = new Name("1"); // False person.Name = null; // True binding.Unbind(); // We can also create an observable from an expression: var d = person.Observe(x => x.Age == null | (x.Age > 33 & x.Age < 35)) .Subscribe(x => Console.WriteLine(x)); person.Age = 34; // True person.Age = 36; // False person.Age = null; // True d.Dispose(); // We can also create an accessor func: Func <Person, BindingResult <bool> > accessor = prototype.ToFunc(); Console.WriteLine(accessor(null)); // False Console.WriteLine(accessor(person)); // True }
public static void Bind <TGraph, TResult>(TGraph graph, BindingResult <TResult> expected, IRootBinding <TGraph, TResult> actual) { None(actual); actual.Bind(graph); Some(expected, actual); actual.Unbind(); None(actual); }
public static void Bind <TGraph, TResult>(TGraph graph, TResult expected, IRootBinding <TGraph, TResult> actual) { Bind(graph, BindingResult.Some(expected), actual); }