public static void ClearAllBindings(object targetObjectOrType) { if (targetObjectOrType == null) { throw new ArgumentNullException("targetObjectOrType"); } lock (instances) { int hashCode = targetObjectOrType.GetHashCode(); foreach (var key in instances.Keys.Where(kvp => kvp.Value == hashCode).ToList()) { var list = instances[key]; for (int i = list.Count - 1; i >= 0; i--) { DumbBinding binding = list[i]; if (object.Equals(targetObjectOrType, binding.Target.TargetObject) || binding.Target.TargetObject == null) { binding.Clear(); list.RemoveAt(i); } } if (list.Count == 0) { instances.Remove(key); } } } }
public static DumbBinding SetBinding(DumbBindingTarget target, BindingBase bindingToSource) { lock (instances) { if (target == null) { throw new ArgumentNullException("target"); } DumbBinding result = new DumbBinding(bindingToSource, target); ClearBinding(target); object targetObject = target.TargetObject; if (targetObject == null) { throw new ArgumentException("target.TargetObject is no longer alive.", "target"); } KeyValuePair <int, int> key = new KeyValuePair <int, int>(target.GetHashCode(), targetObject.GetHashCode()); if (instances.ContainsKey(key)) { instances[key].Add(result); } else { instances.Add(key, new List <DumbBinding>() { result }); } return(result); } }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { DumbBinding other = obj as DumbBinding; return(other != null && ((this.SourcePropertyChangedHandle != null && PropertyChangedHandle.Equals(this.SourcePropertyChangedHandle, other.SourcePropertyChangedHandle, false)) || (this.SourceMultiPropertyChangedHandle != null && MultiPropertyChangedHandle.Equals(this.SourceMultiPropertyChangedHandle, other.SourceMultiPropertyChangedHandle, false))) && object.Equals(this.Target, other.Target)); }
public static void ClearBinding(DumbBindingTarget target) { if (target == null) { throw new ArgumentNullException("target"); } object targetObject = target.TargetObject; if (targetObject == null) { throw new ArgumentException("target.TargetObject is no longer alive.", "target"); } lock (instances) { KeyValuePair <int, int> key = new KeyValuePair <int, int>(target.GetHashCode(), targetObject.GetHashCode()); if (instances.ContainsKey(key)) { var list = instances[key]; for (int i = list.Count - 1; i >= 0; i--) { DumbBinding binding = list[i]; if (object.Equals(target, binding.Target) || binding.Target.TargetObject == null) { binding.Clear(); list.RemoveAt(i); } } if (list.Count == 0) { instances.Remove(key); } } } }