Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ValueInfo.cs « Xamarin.PropertyEditing - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9855c9041cdcabe6396bf3bd1c0344dd616ad1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;

namespace Xamarin.PropertyEditing
{
	/// <remarks>
	/// <para>The <see cref="Source"/> and <see cref="ValueDescriptor"/> for the value must match for two ValueInfos to be considered equal.</para>
	/// </remarks>
	public class ValueInfo<T> : IEquatable<ValueInfo<T>>
	{
		public T Value
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a descriptor of the value source, such as a resource reference or binding description.
		/// </summary>
		public object ValueDescriptor
		{
			get;
			set;
		}

		public ValueSource Source
		{
			get;
			set;
		}

		public string CustomExpression
		{
			get;
			set;
		}

		public bool Equals (ValueInfo<T> other)
		{
			if (ReferenceEquals (null, other))
				return false;
			if (ReferenceEquals (this, other))
				return true;

			return EqualityComparer<T>.Default.Equals (Value, other.Value) && Equals (ValueDescriptor, other.ValueDescriptor) && Source == other.Source && CustomExpression == other.CustomExpression;
		}

		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 ((ValueInfo<T>) obj);
		}

		public override int GetHashCode ()
		{
			unchecked {
				var hashCode = EqualityComparer<T>.Default.GetHashCode (Value);
				hashCode = (hashCode * 397) ^ (ValueDescriptor?.GetHashCode () ?? 0);
				hashCode = (hashCode * 397) ^ (int) Source;
				hashCode = (hashCode * 397) ^ (CustomExpression?.GetHashCode() ?? 0);
				return hashCode;
			}
		}

		public static bool operator == (ValueInfo<T> left, ValueInfo<T> right)
		{
			return Equals (left, right);
		}

		public static bool operator != (ValueInfo<T> left, ValueInfo<T> right)
		{
			return !Equals (left, right);
		}
	}
}