Permalink
Switch branches/tags
tag-test3 tag-test2 tag-test1 rui-3.0.0 release-3.4.0-rc1.3 release-3.4.0-rc1.2 release-3.4.0-rc1.1 release-3.4.0-rc1 release-3.3.0-sr1.2 release-3.3.0-sr1.1 release-3.3.0-sr1 release-3.3.0-rc0 release-3.2.0 release-3.2.0-sr1 release-3.1.0-sr3 release-3.1.0-sr2 release-3.1.0-sr1.1 release-3.1.0-sr1 release-3.1.0-rc1 release-3.0.0-sr4.1 release-3.0.0-sr4 release-3.0.0-sr3 release-3.0.0-sr2 release-3.0.0-sr1 release-3.0.0-rc2 release-3.0.0-rc1 release-2.5.1 release-2.5.1-sr4 release-2.5.1-sr3 release-2.5.1-sr2 release-2.5.1-sr1 release-2.5.0 release-2.5.0-sr5 release-2.5.0-sr4 release-2.5.0-sr3 release-2.5.0-sr2 release-2.5.0-sr1 release-2.4.99-rc1 release-2.4.0 release-2.4.0-sr6 release-2.4.0-sr5 release-2.4.0-sr4 release-2.4.0-sr3 release-2.4.0-sr2 release-2.4.0-sr1 release-2.4.0-rc2 release-2.3.5 release-2.3.4 release-2.3.4-sr6 release-2.3.4-sr5 release-2.3.4-sr4 release-2.3.4-sr3 release-2.3.4-sr2 release-2.3.4-sr1 release-2.3.3 release-2.3.3-sr2 release-2.3.3-sr1.1 release-2.3.3-sr1 release-2.3.3-hf1 release-2.3.2 release-2.3.2-hf1 release-2.3.1 release-2.3.0 release-2.3.0-hf1 release-2.2.0 release-2.2.0-hf1 beta-cycle6buildtest beta-9.99.99-rui beta-9.9.999-rui beta-9.9.99-rui beta-9.9.15.5-rui beta-9.9.9.9-rui beta-9.9.9-rui beta-9.9.8-rui beta-3.5.0-pre1.1 beta-3.5.0-pre1 beta-3.4.0-rui beta-3.4.0-pre2.2 beta-3.4.0-pre2.1 beta-3.4.0-pre2 beta-3.4.0-pre1 beta-3.3.0-pre3 beta-3.3.0-pre2 beta-3.3.0-pre1 beta-3.2.0-pre3 beta-3.2.0-pre2 beta-3.2.0-pre1.1 beta-3.2.0-pre1 beta-3.1.0-pre4.1 beta-3.1.0-pre4 beta-3.1.0-pre3 beta-3.1.0-pre2.3 beta-3.1.0-pre2.2 beta-3.1.0-pre2 beta-3.1.0-pre1.2 beta-3.1.0-pre1 beta-3.0.0-rui beta-3.0.0-pre4.4 beta-3.0.0-pre4.3 beta-3.0.0-pre4.2
Nothing to show
Find file Copy path
a9a68c6 Aug 2, 2018
2 contributors

Users who have contributed to this file

@StephaneDelcroix @jassmith
137 lines (109 sloc) 3.22 KB
using System;
using System.Collections;
using System.Runtime.CompilerServices;
namespace Xamarin.Forms
{
public abstract class BindingBase
{
static readonly ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext> SynchronizedCollections = new ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext>();
BindingMode _mode = BindingMode.Default;
string _stringFormat;
object _targetNullValue;
object _fallbackValue;
internal BindingBase()
{
}
public BindingMode Mode
{
get { return _mode; }
set
{
if ( value != BindingMode.Default
&& value != BindingMode.OneWay
&& value != BindingMode.OneWayToSource
&& value != BindingMode.TwoWay
&& value != BindingMode.OneTime)
throw new ArgumentException("mode is not a valid BindingMode", "mode");
ThrowIfApplied();
_mode = value;
}
}
public string StringFormat
{
get { return _stringFormat; }
set
{
ThrowIfApplied();
_stringFormat = value;
}
}
public object TargetNullValue
{
get { return _targetNullValue; }
set {
ThrowIfApplied();
_targetNullValue = value;
}
}
public object FallbackValue {
get => _fallbackValue;
set {
ThrowIfApplied();
_fallbackValue = value;
}
}
internal bool AllowChaining { get; set; }
internal object Context { get; set; }
internal bool IsApplied { get; private set; }
public static void DisableCollectionSynchronization(IEnumerable collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
SynchronizedCollections.Remove(collection);
}
public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
if (callback == null)
throw new ArgumentNullException(nameof(callback));
SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
}
protected void ThrowIfApplied()
{
if (IsApplied)
throw new InvalidOperationException("Can not change a binding while it's applied");
}
internal virtual void Apply(bool fromTarget)
{
IsApplied = true;
}
internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
{
IsApplied = true;
}
internal abstract BindingBase Clone();
internal virtual object GetSourceValue(object value, Type targetPropertyType)
{
if (value == null && TargetNullValue != null)
return TargetNullValue;
if (StringFormat != null)
return string.Format(StringFormat, value);
return value;
}
internal virtual object GetTargetValue(object value, Type sourcePropertyType)
{
return value;
}
internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
return SynchronizedCollections.TryGetValue(collection, out synchronizationContext);
}
internal virtual void Unapply(bool fromBindingContextChanged = false)
{
IsApplied = false;
}
}
}