-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataObject.cs
88 lines (80 loc) · 2.55 KB
/
DataObject.cs
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
using Prism.Mvvm;
using System;
namespace Opus.Services.Implementation.Data
{
/// <summary>
/// General abstract base class for storing data into the database.
/// </summary>
/// <typeparam name="T">Type of the data to store.</typeparam>
public abstract class DataObject<T> : BindableBase where T : DataObject<T>
{
/// <summary>
/// Id for individualization.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// Create a new data object. Id will be generated automatically.
/// </summary>
public DataObject()
{
Id = Guid.NewGuid();
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object? obj) => obj is DataObject<T> other && Equals(other);
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(DataObject<T> other)
{
return CheckEquality((T)this, (T)other);
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator ==(DataObject<T> a, DataObject<T> b)
{
if (a is null && b is null)
return true;
if (a is null || b is null)
return false;
DataObject<T> comparer = a ?? b;
return comparer.CheckEquality((T)a, (T)b);
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator !=(DataObject<T> a, DataObject<T> b)
{
if (a is null && b is null)
return true;
if (a is null || b is null)
return false;
DataObject<T> comparer = a ?? b;
return !comparer.CheckEquality((T)a, (T)b);
}
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public abstract override int GetHashCode();
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="current"></param>
/// <param name="other"></param>
/// <returns></returns>
protected abstract bool CheckEquality(T current, T other);
}
}