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; }
72 _targetNullValue = value;
76 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
77 [EditorBrowsable(EditorBrowsableState.Never)]
78 public object FallbackValue
80 get => _fallbackValue;
84 _fallbackValue = value;
88 internal bool AllowChaining { get; set; }
90 internal object Context { get; set; }
92 internal bool IsApplied { get; private set; }
95 /// Stops synchronization on the collection.
97 /// <param name="collection">The collection on which to stop synchronization.</param>
98 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public static void DisableCollectionSynchronization(IEnumerable collection)
102 if (collection == null)
103 throw new ArgumentNullException(nameof(collection));
105 SynchronizedCollections.Remove(collection);
108 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback)
112 if (collection == null)
113 throw new ArgumentNullException(nameof(collection));
114 if (callback == null)
115 throw new ArgumentNullException(nameof(callback));
117 SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback));
121 /// Throws an InvalidOperationException if the binding has been applied.
123 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 protected void ThrowIfApplied()
128 throw new InvalidOperationException("Can not change a binding while it's applied");
131 internal virtual void Apply(bool fromTarget)
136 internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
141 internal abstract BindingBase Clone();
143 internal virtual object GetSourceValue(object value, Type targetPropertyType)
145 if (value == null && TargetNullValue != null)
146 return TargetNullValue;
147 if (StringFormat != null)
148 return string.Format(StringFormat, value);
153 internal virtual object GetTargetValue(object value, Type sourcePropertyType)
158 internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext)
160 if (collection == null)
161 throw new ArgumentNullException(nameof(collection));
163 return SynchronizedCollections.TryGetValue(collection, out synchronizationContext);
166 internal virtual void Unapply(bool fromBindingContextChanged = false)