public void Apply <TSource, TTarget>(BindingInfo <TSource, TTarget> info) { if (info.Mode.HasFlag(BindingMode.OneWay)) { var sourceGetter = info.Source.Compile(); var targetSetter = this.CreateSetter(info.Target); var dependencies = new DependencyCollector(info.Source).Dependencies; var watcher = new DependencyWatcher(dependencies, BindingMode.OneWay, info.ErrorOptions); var handler = this.CreateHandler(sourceGetter, targetSetter, info.Converter.ConvertTo); watcher.ValueChanged += handler; watcher.BeginWatch(); } if (info.Mode.HasFlag(BindingMode.OneWayToSource)) { var targetGetter = info.Target.Compile(); var sourceSetter = this.CreateSetter(info.Source); var dependencies = new DependencyCollector(info.Target).Dependencies; var watcher = new DependencyWatcher(dependencies, BindingMode.OneWayToSource, info.ErrorOptions); var handler = this.CreateHandler(targetGetter, sourceSetter, info.Converter.ConvertFrom); watcher.ValueChanged += handler; watcher.BeginWatch(); } }
public void ShouldCollectNotifiableRootAsDependency() { var source = new Source(); var expression = (Expression<Func<string>>)(() => source.Name); var root = new DependencyCollector(expression).Dependencies.Single(); Assert.AreEqual("Name", root.PropertyName); Assert.IsEmpty(root.SubDependencies); }
public void ShouldCollectLinksAsDependenciesIfNotifiable() { var source = new Source(); var expression = (Expression<Func<string>>)(() => source.Inner.Name); var root = new DependencyCollector(expression).Dependencies.Single(); Assert.AreEqual("Inner", root.PropertyName); var subDependency = root.SubDependencies.Single(); Assert.AreEqual("Name", subDependency.PropertyName); }