Rename IPropertyChangedBinding -> IEventBinding

This commit is contained in:
Antony Male 2014-04-23 17:45:26 +01:00
parent afe8b9c20f
commit f7210b8aa9
4 changed files with 13 additions and 13 deletions

View File

@ -12,14 +12,14 @@ namespace Stylet
/// <summary>
/// A binding to a PropertyChanged event, which can be used to unbind the binding
/// </summary>
public interface IPropertyChangedBinding
public interface IEventBinding
{
void Unbind();
}
public static class PropertyChangedExtensions
{
internal class StrongPropertyChangedBinding : IPropertyChangedBinding
internal class StrongPropertyChangedBinding : IEventBinding
{
private WeakReference<INotifyPropertyChanged> inpc;
private PropertyChangedEventHandler handler;
@ -48,7 +48,7 @@ namespace Stylet
/// <param name="targetSelector">MemberExpression selecting the property to observe for changes (e.g x => x.PropertyName)</param>
/// <param name="handler">Handler called whenever that property changed</param>
/// <returns>Something which can be used to undo the binding. You can discard it if you want</returns>
public static IPropertyChangedBinding Bind<TBindTo, TMember>(this TBindTo target, Expression<Func<TBindTo, TMember>> targetSelector, Action<TMember> handler) where TBindTo : class, INotifyPropertyChanged
public static IEventBinding Bind<TBindTo, TMember>(this TBindTo target, Expression<Func<TBindTo, TMember>> targetSelector, Action<TMember> handler) where TBindTo : class, INotifyPropertyChanged
{
var propertyName = targetSelector.NameForProperty();
var propertyAccess = targetSelector.Compile();

View File

@ -32,7 +32,7 @@ namespace Stylet
/// <param name="selector">Expression for selecting the property to observe, e.g. x => x.PropertyName</param>
/// <param name="handler">Handler to be called when that property changes</param>
/// <returns>A resource which can be used to undo the binding</returns>
protected IPropertyChangedBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
protected IEventBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
where TSource : class, INotifyPropertyChanged
{
return this.weakEventManager.BindWeak(source, selector, handler);

View File

@ -10,20 +10,20 @@ namespace Stylet
{
public interface IWeakEventManager
{
IPropertyChangedBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
IEventBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
where TSource : class, INotifyPropertyChanged;
}
internal class WeakPropertyBinding<TSource, TProperty> : IPropertyChangedBinding where TSource : class, INotifyPropertyChanged
internal class WeakPropertyBinding<TSource, TProperty> : IEventBinding where TSource : class, INotifyPropertyChanged
{
// Make sure we don't end up retaining the source
private readonly WeakReference<TSource> source;
private readonly string propertyName;
private readonly Func<TSource, TProperty> valueSelector;
private readonly Action<TProperty> handler;
private readonly Action<IPropertyChangedBinding> remover;
private readonly Action<IEventBinding> remover;
public WeakPropertyBinding(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler, Action<IPropertyChangedBinding> remover)
public WeakPropertyBinding(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler, Action<IEventBinding> remover)
{
this.source = new WeakReference<TSource>(source);
this.propertyName = selector.NameForProperty();
@ -55,9 +55,9 @@ namespace Stylet
public class WeakEventManager : IWeakEventManager
{
private object bindingsLock = new object();
private List<IPropertyChangedBinding> bindings = new List<IPropertyChangedBinding>();
private List<IEventBinding> bindings = new List<IEventBinding>();
public IPropertyChangedBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
public IEventBinding BindWeak<TSource, TProperty>(TSource source, Expression<Func<TSource, TProperty>> selector, Action<TProperty> handler)
where TSource : class, INotifyPropertyChanged
{
// So, the handler's target might point to the class that owns us, or it might point to a compiler-generated class
@ -82,7 +82,7 @@ namespace Stylet
return binding;
}
internal void Remove(IPropertyChangedBinding binding)
internal void Remove(IEventBinding binding)
{
lock (this.bindingsLock)
{

View File

@ -38,13 +38,13 @@ namespace StyletUnitTests
public string LastFoo;
private WeakEventManager weakEventManager = new WeakEventManager();
public IPropertyChangedBinding BindStrong(NotifyingClass notifying)
public IEventBinding BindStrong(NotifyingClass notifying)
{
// Must make sure the compiler doesn't generate an inner class for this, otherwise we're not testing the right thing
return notifying.Bind(x => x.Foo, x => this.LastFoo = x);
}
public IPropertyChangedBinding BindWeak(NotifyingClass notifying)
public IEventBinding BindWeak(NotifyingClass notifying)
{
return this.weakEventManager.BindWeak(notifying, x => x.Foo, x => this.LastFoo = x);
}