using System;
using System.Collections.Generic;
namespace Xamarin.PropertyEditing
{
///
/// The and for the value must match for two ValueInfos to be considered equal.
///
public class ValueInfo : IEquatable>
{
public T Value
{
get;
set;
}
///
/// Gets or sets a descriptor of the value source, such as a resource reference or binding description.
///
public object ValueDescriptor
{
get;
set;
}
public ValueSource Source
{
get;
set;
}
public string CustomExpression
{
get;
set;
}
public bool Equals (ValueInfo other)
{
if (ReferenceEquals (null, other))
return false;
if (ReferenceEquals (this, other))
return true;
return EqualityComparer.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) obj);
}
public override int GetHashCode ()
{
unchecked {
var hashCode = EqualityComparer.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 left, ValueInfo right)
{
return Equals (left, right);
}
public static bool operator != (ValueInfo left, ValueInfo right)
{
return !Equals (left, right);
}
}
}