using System;
using System.Collections.Generic;
namespace ZeroLevel.Services.Async
{
///
/// Represents an item retrieved from one of the asynchronous collections.
///
public struct AnyResult
: IEquatable>
{
public AnyResult(T value, int collectionIndex)
{
Value = value;
CollectionIndex = collectionIndex;
}
///
/// Gets the item retrieved from a collection.
///
public T Value { get; }
///
/// Gets the index of the collection the item was retrieved from.
///
public int CollectionIndex { get; }
public override int GetHashCode()
{
unchecked
{
const int prime = -1521134295;
int hash = 12345701;
hash = hash * prime + EqualityComparer.Default.GetHashCode(Value);
hash = hash * prime + EqualityComparer.Default.GetHashCode(CollectionIndex);
return hash;
}
}
public bool Equals(AnyResult other) => EqualityComparer.Default.Equals(Value, other.Value) && EqualityComparer.Default.Equals(CollectionIndex, other.CollectionIndex);
public override bool Equals(object obj) => obj is AnyResult && Equals((AnyResult)obj);
public static bool operator ==(AnyResult x, AnyResult y) => x.Equals(y);
public static bool operator !=(AnyResult x, AnyResult y) => !x.Equals(y);
}
}