2 using System.Collections;
3 using System.Runtime.CompilerServices;
4 using System.ComponentModel;
6 namespace Tizen.NUI.Binding
9 /// An abstract class that provides a BindingMode and a formatting option.
11 [EditorBrowsable(EditorBrowsableState.Never)]
12 public abstract class BindingBase
14 static readonly ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext> SynchronizedCollections = new ConditionalWeakTable<IEnumerable, CollectionSynchronizationContext>();
16 BindingMode _mode = BindingMode.Default;
18 object _targetNullValue;
19 object _fallbackValue;
21 internal BindingBase()
26 /// Gets or sets the mode for this binding.
28 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public BindingMode Mode
35 if ( value != BindingMode.Default
36 && value != BindingMode.OneWay
37 && value != BindingMode.OneWayToSource
38 && value != BindingMode.TwoWay
39 && value != BindingMode.OneTime)
40 throw new ArgumentException("mode is not a valid BindingMode", nameof(Mode));
49 /// Gets or sets the string format for this binding.
51 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public string StringFormat
55 get { return _stringFormat; }
60 _stringFormat = value;
64 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public object TargetNullValue
68 get { return _targetNullValue; }
71 _targetNullValue = value;
75 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public object FallbackValue {
78 get => _fallbackValue;
81 _fallbackValue = value;
85 internal bool AllowChaining { get; set; }
87 internal object Context { get; set; }
89 internal bool IsApplied { get; private set; }
92 /// Stops synchronization on the collection.
94 /// <param name="collection">The collection on which to stop synchronization.</param>
95 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public static void DisableCollectionSynchronization(IEnumerable collection)
99 if (collection == null)
100 throw new ArgumentNullException(nameof(collection));
102 SynchronizedCollections.Remove(collection);
105 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
109 if (collection == null)
110 throw new ArgumentNullException(nameof(collection));
111 if (callback == null)
112 throw new ArgumentNullException(nameof(callback));
114 SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
118 /// Throws an InvalidOperationException if the binding has been applied.
120 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 protected void ThrowIfApplied()
125 throw new InvalidOperationException("Can not change a binding while it's applied");
128 internal virtual void Apply(bool fromTarget)
133 internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
138 internal abstract BindingBase Clone();
140 internal virtual object GetSourceValue(object value, Type targetPropertyType)
142 if (value == null && TargetNullValue != null)
143 return TargetNullValue;
144 if (StringFormat != null)
145 return string.Format(StringFormat, value);
150 internal virtual object GetTargetValue(object value, Type sourcePropertyType)
155 internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext)
157 if (collection == null)
158 throw new ArgumentNullException(nameof(collection));
160 return SynchronizedCollections.TryGetValue(collection, out synchronizationContext);
163 internal virtual void Unapply(bool fromBindingContextChanged = false)