Repository navigation
Expand file tree
/
Copy pathError.cs
More file actions
117 lines (105 loc) · 3.89 KB
/
Copy pathError.cs
File metadata and controls
117 lines (105 loc) · 3.89 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
namespace DynamicData.Kernel
{
/// <summary>
/// An error container used to report errors from within dynamic data operators
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
public sealed class Error<TObject, TKey> : IKeyValue<TObject, TKey>, IEquatable<Error<TObject, TKey>>
{
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object"/> class.
/// </summary>
public Error(Exception exception, TObject value, TKey key)
{
Exception = exception;
Value = value;
Key = key;
}
/// <summary>
/// Gets the key.
/// </summary>
public TKey Key { get; }
/// <summary>
/// Gets the object.
/// </summary>
public TObject Value { get; }
/// <summary>
/// The exception.
/// </summary>
public Exception Exception { get; }
#region Equality members
/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator ==(Error<TObject, TKey> left, Error<TObject, TKey> right)
{
return Equals(left, right);
}
/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator !=(Error<TObject, TKey> left, Error<TObject, TKey> right)
{
return !Equals(left, right);
}
/// <summary>
/// Equalses the specified other.
/// </summary>
/// <param name="other">The other.</param>
/// <returns></returns>
public bool Equals(Error<TObject, TKey> other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return EqualityComparer<TKey>.Default.Equals(Key, other.Key) && EqualityComparer<TObject>.Default.Equals(Value, other.Value) && Equals(Exception, other.Exception);
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <returns>
/// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
/// <param name="obj">Another object to compare to. </param>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is Error<TObject, TKey> && Equals((Error<TObject, TKey>)obj);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode()
{
unchecked
{
int hashCode = EqualityComparer<TKey>.Default.GetHashCode(Key);
hashCode = (hashCode * 397) ^ EqualityComparer<TObject>.Default.GetHashCode(Value);
hashCode = (hashCode * 397) ^ (Exception != null ? Exception.GetHashCode() : 0);
return hashCode;
}
}
#endregion
/// <inheritdoc />
public override string ToString()
{
return $"Key: {Key}, Value: {Value}, Exception: {Exception}";
}
}
}