Repository navigation
Expand file tree
/
Copy pathError.cs
More file actions
107 lines (90 loc) · 3.11 KB
/
Copy pathError.cs
File metadata and controls
107 lines (90 loc) · 3.11 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
// Copyright (c) 2011-2019 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
#pragma warning disable 1591
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
public static bool operator ==(Error<TObject, TKey> left, Error<TObject, TKey> right)
{
return Equals(left, right);
}
public static bool operator !=(Error<TObject, TKey> left, Error<TObject, TKey> right)
{
return !Equals(left, right);
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
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}";
}
}
}