private void InternalUnBind() { if (_CurrentBinding != null) { _CurrentBinding.UnBind(); _CurrentBinding = null; } }
/// <summary> /// Recreate the link between final source property and final destination property /// </summary> private void RecreateRealBinding() { if (_CurrentBinding != null) { _CurrentBinding.UnBind(); } _CurrentBinding = null; PathItem destPathItem = _DestinationBinding.LastItem; //last item path (property to bind) if (destPathItem == null || destPathItem.Source == null) { return; } PathItem srcPathItem = _SourceBinding.LastItem; if (srcPathItem == null || srcPathItem.Source == null) { return; } srcPathItem.ArrayWrapper = null; object source, destination; PropertyInfo piSource, piDestination; source = srcPathItem.Source.Target; destination = destPathItem.Source.Target; bool arrayWrapperIsValid; //special case if it's an array if (srcPathItem.IsArray) { piSource = null; srcPathItem.ArrayWrapper = CreateArrayWrapper(srcPathItem, srcPathItem, out arrayWrapperIsValid, delegate() { if (_CurrentBinding != null) { _CurrentBinding.ForceUpdate(); } else { RecreateRealBinding(); } }); if (srcPathItem.ArrayWrapper == null) { return; } piSource = srcPathItem.ArrayWrapper.GetType().GetProperty("ArrayValue"); source = srcPathItem.ArrayWrapper; if (!arrayWrapperIsValid) { return; } } else { piSource = source.GetType().GetProperty(srcPathItem.PropertyName); } if (destPathItem.IsArray) { piDestination = null; destPathItem.ArrayWrapper = CreateArrayWrapper(srcPathItem, destPathItem, out arrayWrapperIsValid, null); if (destPathItem.ArrayWrapper == null) { return; } piDestination = destPathItem.ArrayWrapper.GetType().GetProperty("ArrayValue"); destination = destPathItem.ArrayWrapper; } else { piDestination = destination.GetType().GetProperty(destPathItem.PropertyName); } Type t = typeof(RealBinding <,>); Type realBindingType = t.MakeGenericType(piSource.PropertyType, piDestination.PropertyType); _CurrentBinding = (IRealBinding)Activator.CreateInstance(realBindingType); _CurrentBinding.Bind(source, piSource, destination, piDestination, _Converter, _ApplyBindingContext); _CurrentBinding.ForceUpdate(); }