summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Pages/DataItem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Pages/DataItem.cs')
-rw-r--r--Xamarin.Forms.Pages/DataItem.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages/DataItem.cs b/Xamarin.Forms.Pages/DataItem.cs
new file mode 100644
index 00000000..62af919c
--- /dev/null
+++ b/Xamarin.Forms.Pages/DataItem.cs
@@ -0,0 +1,86 @@
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+
+namespace Xamarin.Forms.Pages
+{
+ public class DataItem : IDataItem, INotifyPropertyChanged
+ {
+ string _name;
+ object _val;
+
+ public DataItem()
+ {
+ }
+
+ public DataItem(string name, object value)
+ {
+ _name = name;
+ _val = value;
+ }
+
+ public string Name
+ {
+ get { return _name; }
+ set
+ {
+ if (_name == value)
+ return;
+ _name = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public object Value
+ {
+ get { return _val; }
+ set
+ {
+ if (_val == value)
+ return;
+ _val = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+ if (ReferenceEquals(this, obj))
+ return true;
+ if (obj.GetType() != GetType())
+ return false;
+ return Equals((DataItem)obj);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return ((_name?.GetHashCode() ?? 0) * 397) ^ (_val?.GetHashCode() ?? 0);
+ }
+ }
+
+ public static bool operator ==(DataItem left, DataItem right)
+ {
+ return Equals(left, right);
+ }
+
+ public static bool operator !=(DataItem left, DataItem right)
+ {
+ return !Equals(left, right);
+ }
+
+ protected bool Equals(DataItem other)
+ {
+ return string.Equals(_name, other._name) && Equals(_val, other._val);
+ }
+
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+} \ No newline at end of file