-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdValueObject.cs
More file actions
65 lines (59 loc) · 2.75 KB
/
IdValueObject.cs
File metadata and controls
65 lines (59 loc) · 2.75 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
using BeyondNetCode.Shell.Ddd.Helpers;
namespace BeyondNetCode.Shell.Ddd
{
/// <summary>
/// Represents an identifier value object.
/// </summary>
public class IdValueObject : ValueObject<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="IdValueObject"/> class with the specified value.
/// </summary>
/// <param name="value">The GUID value of the identifier.</param>
protected IdValueObject(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="IdValueObject"/> with a random identifier value.
/// </summary>
/// <returns>A new <see cref="IdValueObject"/> instance with a randomly generated GUID.</returns>
public static IdValueObject Create()
{
return new IdValueObject(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="IdValueObject"/> with the specified identifier value as a string.
/// </summary>
/// <param name="value">The string representation of the identifier value.</param>
/// <returns>A new <see cref="IdValueObject"/> instance with the specified GUID value.</returns>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="value"/> is null.</exception>
public static IdValueObject Load(string value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));
return new IdValueObject(IdHelper.GetGuidFromString(value));
}
/// <summary>
/// Creates a new instance of the <see cref="IdValueObject"/> with the specified identifier value as a GUID.
/// </summary>
/// <param name="value">The GUID value of the identifier.</param>
/// <returns>A new <see cref="IdValueObject"/> instance with the specified GUID value.</returns>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="value"/> is null.</exception>
public static IdValueObject Load(Guid value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));
return new IdValueObject(value);
}
/// <summary>
/// Gets the components that are used to determine equality for the value object.
/// </summary>
/// <returns>An enumerable of objects representing the equality components.</returns>
protected override IEnumerable<object> GetEqualityComponents()
{
yield return GetValue();
}
/// <summary>
/// Gets the default value of the <see cref="IdValueObject"/>, which is an empty GUID.
/// </summary>
public static IdValueObject DefaultValue => new IdValueObject(Guid.Empty);
}
}