public bool Equals(Maybe <T> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(HasValue.Equals(other.HasValue) && EqualityComparer <T> .Default.Equals(Value, other.Value)); }
/// <inheritdoc /> public bool Equals(Optional <T> other) { if (!HasValue) { return(!other.HasValue); } if (!other.HasValue) { return(false); } if (_value is null && other._value is null) { return(true); } if (_value is null || other._value is null) { return(false); } return(HasValue.Equals(other.HasValue) && EqualityComparer <T> .Default.Equals(_value, other._value)); }
/// <summary> /// Determines whether the specified <see cref="Optional{T}" /> is equal to this instance. /// </summary> /// <param name="other">The <see cref="Optional{T}" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="Optional{T}" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> public bool Equals(Optional <T> other) { if (HasValue.Equals(other.HasValue)) { if (typeof(IEnumerable).IsAssignableFrom(typeof(T))) { var enumerable1 = (IEnumerable)_value; var enumerable2 = (IEnumerable)other._value; if (enumerable1 == null && enumerable2 == null) { return(true); } if (enumerable1 == null || enumerable2 == null) { return(false); } IEnumerator enumerator1 = enumerable1.GetEnumerator(); IEnumerator enumerator2 = enumerable2.GetEnumerator(); while (enumerator1.MoveNext()) { if (!(enumerator2.MoveNext() && EqualityComparer <object> .Default.Equals(enumerator1.Current, enumerator2.Current))) { return(false); } } return(!enumerator2.MoveNext()); } return(EqualityComparer <T> .Default.Equals(_value, other._value)); } return(false); }
protected bool Equals(Maybe <T> other) { return(EqualityComparer <T> .Default.Equals(Value, other.Value) && string.Equals(Error, other.Error) && HasValue.Equals(other.HasValue)); }
public bool Equals(Maybe <T> other) => EqualityComparer <T> .Default.Equals(_value, other._value) && HasValue.Equals(other.HasValue);
public bool Equals(Optional <T> other) { return(HasValue.Equals(other.HasValue) && EqualityComparer <T> .Default.Equals(_value, other._value)); }