Skip to content

Commit f6a4ddb

Browse files
chore: Delegate ToString() to encapsulated object (#35)
* chore: Delegate ToString() to encapsulated object * Update src/EntityDb.Abstractions/ValueObjects/TimeStamp.cs Co-authored-by: Chris Philips <[email protected]> Co-authored-by: Chris Philips <[email protected]>
1 parent 7b22441 commit f6a4ddb

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/EntityDb.Abstractions/ValueObjects/Id.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,24 @@ public readonly record struct Id(Guid Value)
1313
/// </summary>
1414
/// <returns>A new, randomly-generated <see cref="Id"/>.</returns>
1515
public static Id NewId() => new(Guid.NewGuid());
16+
17+
/// <summary>
18+
/// Returns a string representation of the value of this instance in
19+
/// registry format.
20+
/// </summary>
21+
/// <returns>
22+
/// The value of this <see cref="Id" />, formatted by using the "D"
23+
/// format specifier as follows:
24+
///
25+
/// <c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>
26+
///
27+
/// where the value of the Id is represented as a series of lowercase
28+
/// hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and
29+
/// separated by hyphens. An example of a return value is
30+
/// "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal
31+
/// digits from a through f to uppercase, call the
32+
/// <see cref="M:System.String.ToUpper" /> method on the returned
33+
/// string.
34+
/// </returns>
35+
public override string? ToString() => Value.ToString();
1636
}

src/EntityDb.Abstractions/ValueObjects/TimeStamp.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Globalization;
23

34
namespace EntityDb.Abstractions.ValueObjects;
45

@@ -12,7 +13,7 @@ public readonly record struct TimeStamp(DateTime Value)
1213
/// The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 1970.
1314
/// </summary>
1415
public static readonly TimeStamp UnixEpoch = new(DateTime.UnixEpoch);
15-
16+
1617
/// <summary>
1718
/// Gets a <see cref="TimeStamp"/> that represents the current date and time on this computer, expressed in UTC.
1819
/// </summary>
@@ -24,4 +25,15 @@ public readonly record struct TimeStamp(DateTime Value)
2425
/// <returns>A <see cref="TimeStamp"/> rounded down to the nearest millisecond.</returns>
2526
public TimeStamp WithMillisecondPrecision() =>
2627
new(Value - TimeSpan.FromTicks(Value.Ticks % TimeSpan.TicksPerMillisecond));
28+
29+
/// <summary>
30+
/// Converts the value of the current <see cref="TimeStamp"/> object to
31+
/// its equivalent string representation using the formatting
32+
/// conventions of the current culture.
33+
/// </summary>
34+
/// <returns>
35+
/// A string representation of the value of the current
36+
/// <see cref="TimeStamp"/> object.
37+
/// </returns>
38+
public override string? ToString() => Value.ToString(CultureInfo.CurrentCulture);
2739
}

src/EntityDb.Abstractions/ValueObjects/VersionNumber.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@ public readonly record struct VersionNumber(ulong Value)
1616
/// </summary>
1717
/// <returns>The next version number.</returns>
1818
public VersionNumber Next() => new(Value + 1);
19+
20+
/// <summary>
21+
/// Converts the numeric value of this instance to its equivalent string
22+
/// representation.
23+
/// </summary>
24+
/// <returns>
25+
/// The string representation of the value of this instance, consisting
26+
/// of a sequence of digits ranging from 0 to 9, without a sign or
27+
/// leading zeroes.
28+
/// </returns>
29+
public override string? ToString() => Value.ToString();
1930
}

0 commit comments

Comments
 (0)