Repository navigation
Expand file tree
/
Copy pathItemWithValue.cs
More file actions
75 lines (65 loc) · 2.59 KB
/
Copy pathItemWithValue.cs
File metadata and controls
75 lines (65 loc) · 2.59 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
// Copyright (c) 2011-2023 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.
namespace DynamicData.Kernel;
/// <summary>
/// Container for an item and it's Value from a list.
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <remarks>
/// Initializes a new instance of the <see cref="ItemWithValue{TObject, TValue}"/> struct.
/// Initializes a new instance of the <see cref="ItemWithIndex{T}"/> class.
/// </remarks>
/// <param name="item">The item.</param>
/// <param name="value">The Value.</param>
public readonly struct ItemWithValue<TObject, TValue>(TObject item, TValue value) : IEquatable<ItemWithValue<TObject, TValue>>
{
/// <summary>
/// Gets the item.
/// </summary>
public TObject Item { get; } = item;
/// <summary>
/// Gets the Value.
/// </summary>
public TValue Value { get; } = value;
/// <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 ==(in ItemWithValue<TObject, TValue> left, in ItemWithValue<TObject, TValue> right) => 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 !=(in ItemWithValue<TObject, TValue> left, in ItemWithValue<TObject, TValue> right) => !Equals(left, right);
/// <inheritdoc />
public bool Equals(ItemWithValue<TObject, TValue> other) => EqualityComparer<TObject>.Default.Equals(Item, other.Item) && EqualityComparer<TValue>.Default.Equals(Value, other.Value);
/// <inheritdoc />
public override bool Equals(object? obj)
{
if (obj is null)
{
return false;
}
return obj is ItemWithValue<TObject, TValue> itemWithValue && Equals(itemWithValue);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
return (Item is null ? 0 : EqualityComparer<TObject>.Default.GetHashCode(Item) * 397) ^ (Value is null ? 0 : EqualityComparer<TValue>.Default.GetHashCode(Value));
}
}
/// <inheritdoc />
public override string ToString() => $"{Item} ({Value})";
}