// Needed for NET40 #if !NET_4_6 using System; namespace LinqInternal.Threading.Needles { [Serializable] [System.Diagnostics.DebuggerNonUserCode] internal struct ExceptionStructNeedle : INeedle, IEquatable> { private readonly Exception _exception; public ExceptionStructNeedle(Exception exception) { _exception = exception; } public Exception Exception { get { return _exception; } } T INeedle.Value { get { throw _exception; } set { throw new NotSupportedException(); } } public bool IsAlive { get { return false; } } public T Value { get { throw _exception; } } public static explicit operator Exception(ExceptionStructNeedle needle) { return needle._exception; } public static implicit operator ExceptionStructNeedle(Exception exception) { return new ExceptionStructNeedle(exception); } public static bool operator !=(ExceptionStructNeedle left, ExceptionStructNeedle right) { return NotEqualsExtracted(left, right); } public static bool operator ==(ExceptionStructNeedle left, ExceptionStructNeedle right) { return EqualsExtracted(left, right); } public override bool Equals(object obj) { if (obj is ExceptionStructNeedle) { return EqualsExtracted(this, (ExceptionStructNeedle)obj); } return obj is Exception && obj.Equals(_exception); } public bool Equals(ExceptionStructNeedle other) { return EqualsExtracted(this, other); } public override int GetHashCode() { return base.GetHashCode(); } public override string ToString() { if (IsAlive) { return string.Format("", _exception); } return ""; } private static bool EqualsExtracted(ExceptionStructNeedle left, ExceptionStructNeedle right) { var leftException = left._exception; var rightException = right._exception; if (leftException == null) { return rightException == null; } return leftException.Equals(rightException); } private static bool NotEqualsExtracted(ExceptionStructNeedle left, ExceptionStructNeedle right) { var leftException = left._exception; var rightException = right._exception; if (leftException == null) { return rightException != null; } return !leftException.Equals(rightException); } } } #endif