Skip to content

Commit 5de0499

Browse files
committed
Fix XML docs and update for release
1 parent d72c5ad commit 5de0499

File tree

12 files changed

+247
-112
lines changed

12 files changed

+247
-112
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright © 2024 Brian Buvinghausen
3+
Copyright © 2025 Brian Buvinghausen
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
4+
<TargetFrameworks>net9.0;net8.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
55
<Authors>Brian Buvinghausen</Authors>
66
<Company>Buvinghausen Solutions</Company>
7-
<Copyright>Copyright © 2024 Brian Buvinghausen</Copyright>
7+
<Copyright>Copyright © 2025 Brian Buvinghausen</Copyright>
88
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
99
<PackageReadmeFile>README.md</PackageReadmeFile>
1010
<PackageProjectUrl>https://github.com/buvinghausen/SequentialGuid/blob/master/README.md</PackageProjectUrl>

src/SequentialGuid.MongoDB/ExtensionMethods.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
namespace SequentialGuid.MongoDB;
44

55
/// <summary>
6-
/// Helper method to make registering the generator easier
6+
/// Provides extension methods for integrating SequentialGuid functionality with MongoDB.
77
/// </summary>
88
public static class ExtensionMethods
99
{
1010
/// <summary>
11-
/// Registers SequentialGuidGenerator with the Mongo BsonSerializer for all Guid types
11+
/// Registers the <see cref="MongoSequentialGuidGenerator"/> as the ID generator for <see cref="Guid"/> types in MongoDB.
1212
/// </summary>
13-
/// <param name="generator"></param>
14-
public static void RegisterMongoIdGenerator(this SequentialGuidGenerator generator) =>
13+
/// <param name="generator">
14+
/// The instance of <see cref="MongoSequentialGuidGenerator"/> to be registered as the ID generator.
15+
/// </param>
16+
/// <remarks>
17+
/// This method integrates the <see cref="MongoSequentialGuidGenerator"/> with MongoDB's BSON serialization framework,
18+
/// enabling the generation of sequential <see cref="Guid"/> values for MongoDB documents.
19+
/// Sequential GUIDs can improve database indexing performance by reducing fragmentation.
20+
/// </remarks>
21+
public static void RegisterMongoIdGenerator(this MongoSequentialGuidGenerator generator) =>
1522
BsonSerializer.RegisterIdGenerator(typeof(Guid), generator);
1623
}

src/SequentialGuid.MongoDB/SequentialGuidGenerator.cs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,52 @@
33
namespace SequentialGuid.MongoDB;
44

55
/// <summary>
6-
/// Implementation of the <see cref="IIdGenerator" /> interface so it can be used by the Mongo driver
6+
/// Provides a mechanism for generating sequential <see cref="Guid"/> values specifically for use with MongoDB.
77
/// </summary>
8-
public sealed class SequentialGuidGenerator : IIdGenerator
8+
/// <remarks>
9+
/// The <see cref="MongoSequentialGuidGenerator"/> class is designed to integrate seamlessly with MongoDB's BSON serialization framework.
10+
/// It generates sequential <see cref="Guid"/> values to improve database indexing performance by reducing fragmentation.
11+
/// This class implements the <see cref="IIdGenerator"/> interface, making it compatible with MongoDB's ID generation system.
12+
/// </remarks>
13+
public sealed class MongoSequentialGuidGenerator : IIdGenerator
914
{
1015
/// <summary>
11-
/// Gets an instance of SequentialGuidGenerator helpful for calling the registration method
16+
/// Gets the singleton instance of the <see cref="SequentialGuidGenerator"/> class.
1217
/// </summary>
13-
public static SequentialGuidGenerator Instance { get; } = new();
14-
18+
/// <value>
19+
/// The singleton instance of <see cref="SequentialGuidGenerator"/>.
20+
/// </value>
21+
/// <remarks>
22+
/// This property provides a globally accessible instance of the <see cref="MongoSequentialGuidGenerator"/>.
23+
/// It is designed to integrate seamlessly with MongoDB's BSON serialization framework, enabling the generation
24+
/// of sequential <see cref="Guid"/> values for improved database indexing performance.
25+
/// </remarks>
26+
public static MongoSequentialGuidGenerator Instance { get; } = new();
27+
1528
/// <summary>
16-
/// Function to generate value for the _id property when it was empty
29+
/// Generates a new sequential <see cref="Guid"/> to be used as an identifier for a MongoDB document.
1730
/// </summary>
18-
/// <param name="container">Not used</param>
19-
/// <param name="document">Not used</param>
20-
/// <returns>sequential guid</returns>
31+
/// <param name="container">The container object that holds the document. This parameter is not used in the implementation.</param>
32+
/// <param name="document">The document for which the ID is being generated. This parameter is not used in the implementation.</param>
33+
/// <returns>A new sequential <see cref="Guid"/>.</returns>
34+
/// <remarks>
35+
/// This method utilizes the <see cref="SequentialGuidGenerator"/> to generate a sequential <see cref="Guid"/>.
36+
/// Sequential GUIDs are designed to improve performance in scenarios such as database indexing by reducing fragmentation.
37+
/// </remarks>
2138
public object GenerateId(object container, object document) =>
22-
SequentialGuid.SequentialGuidGenerator.Instance.NewGuid();
23-
39+
SequentialGuidGenerator.Instance.NewGuid();
40+
2441
/// <summary>
25-
/// Checks to see if existing value is empty and needs to be replaced
42+
/// Determines whether the specified identifier is considered empty.
2643
/// </summary>
27-
/// <param name="id">Current value from the document</param>
28-
/// <returns>True or false on if GenerateId needs to be invoked</returns>
44+
/// <param name="id">The identifier to evaluate. This can be of any type.</param>
45+
/// <returns>
46+
/// <c>true</c> if the <paramref name="id"/> is either not a <see cref="Guid"/> or is an empty <see cref="Guid"/>; otherwise, <c>false</c>.
47+
/// </returns>
48+
/// <remarks>
49+
/// This method checks if the provided <paramref name="id"/> is either not a <see cref="Guid"/> or represents an empty <see cref="Guid"/> value.
50+
/// It is useful for validating identifiers in scenarios where <see cref="Guid"/> values are expected.
51+
/// </remarks>
2952
public bool IsEmpty(object id) =>
3053
id is not Guid guid || guid == Guid.Empty;
3154
// Pattern matching is life

src/SequentialGuid.NodaTime/ExtensionMethods.cs

Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,108 @@
55
namespace NodaTime;
66

77
/// <summary>
8-
/// Helper functions that utilize NodaTime's Instant struct rather than DateTime
8+
/// Provides extension methods for working with NodaTime's <see cref="Instant"/> and sequential GUID generators.
99
/// </summary>
10+
/// <remarks>
11+
/// This static class contains helper methods to facilitate the creation of sequential GUIDs and
12+
/// conversions between <see cref="Instant"/> and GUID-related types.
13+
/// </remarks>
1014
public static class ExtensionMethods
1115
{
1216
/// <summary>
13-
/// Takes an instance of NodaTime's Instant struct and returns back a sequential guid
17+
/// Generates a new sequential <see cref="Guid"/> based on the specified <see cref="Instant"/> timestamp.
1418
/// </summary>
15-
/// <param name="generator">Extension parameter the singleton instance of the generator</param>
16-
/// <param name="timestamp">Time value in UTC between the Unix epoch and now</param>
17-
/// <returns>sequential guid</returns>
19+
/// <param name="generator">
20+
/// The <see cref="SequentialGuidGenerator"/> instance used to generate the sequential <see cref="Guid"/>.
21+
/// </param>
22+
/// <param name="timestamp">
23+
/// The <see cref="Instant"/> representing the point in time to base the GUID generation on.
24+
/// </param>
25+
/// <returns>
26+
/// A new sequential <see cref="Guid"/> generated using the provided <paramref name="timestamp"/>.
27+
/// </returns>
28+
/// <remarks>
29+
/// This method converts the provided <see cref="Instant"/> to a UTC <see cref="DateTime"/> and uses it
30+
/// to generate a sequential <see cref="Guid"/>. Sequential GUIDs are particularly useful for database
31+
/// indexing and reducing fragmentation.
32+
/// </remarks>
33+
/// <exception cref="ArgumentException">
34+
/// Thrown if the <paramref name="timestamp"/> is outside the valid range for GUID generation.
35+
/// </exception>
1836
public static Guid NewGuid(this SequentialGuidGenerator generator, Instant timestamp) =>
1937
generator.NewGuid(timestamp.ToDateTimeUtc());
20-
38+
2139
/// <summary>
22-
/// Takes an instance of NodaTime's Instant struct and returns back a sequential guid sorted for SQL Server
40+
/// Generates a new sequential <see cref="Guid"/> based on the provided <see cref="Instant"/> timestamp.
2341
/// </summary>
24-
/// <param name="generator">Extension parameter the singleton instance of the generator</param>
25-
/// <param name="timestamp">Time value in UTC between the Unix epoch and now</param>
26-
/// <returns>sequential guid for SQL Server</returns>
42+
/// <param name="generator">
43+
/// The <see cref="SequentialSqlGuidGenerator"/> instance used to generate the sequential GUID.
44+
/// </param>
45+
/// <param name="timestamp">
46+
/// The <see cref="Instant"/> representing the timestamp to base the GUID generation on.
47+
/// </param>
48+
/// <returns>
49+
/// A new sequential <see cref="Guid"/> generated using the specified timestamp.
50+
/// </returns>
51+
/// <remarks>
52+
/// This method converts the provided <see cref="Instant"/> to a UTC <see cref="DateTime"/> and uses it
53+
/// to generate a sequential GUID. Sequential GUIDs are particularly useful in scenarios where maintaining
54+
/// index performance in databases is critical.
55+
/// </remarks>
56+
/// <exception cref="ArgumentException">
57+
/// Thrown if the <paramref name="timestamp"/> is outside the valid range for GUID generation.
58+
/// </exception>
2759
public static Guid NewGuid(this SequentialSqlGuidGenerator generator, Instant timestamp) =>
2860
generator.NewGuid(timestamp.ToDateTimeUtc());
29-
61+
3062
/// <summary>
31-
/// Takes an instance of NodaTime's Instant struct and returns back a sequential SQL guid
63+
/// Generates a new sequential <see cref="SqlGuid"/> based on the specified <see cref="Instant"/> timestamp.
3264
/// </summary>
33-
/// <param name="generator">Extension parameter the singleton instance of the generator</param>
34-
/// <param name="timestamp">Time value in UTC between the Unix epoch and now</param>
35-
/// <returns>sequential SQL guid</returns>
65+
/// <param name="generator">
66+
/// The <see cref="SequentialSqlGuidGenerator"/> instance used to create the sequential <see cref="SqlGuid"/>.
67+
/// </param>
68+
/// <param name="timestamp">
69+
/// The <see cref="Instant"/> representing the point in time to base the sequential <see cref="SqlGuid"/> on.
70+
/// </param>
71+
/// <returns>
72+
/// A new sequential <see cref="SqlGuid"/> corresponding to the provided <see cref="Instant"/>.
73+
/// </returns>
74+
/// <remarks>
75+
/// This method facilitates the creation of sequential <see cref="SqlGuid"/> values, which are particularly
76+
/// useful in database scenarios where maintaining index performance is critical. The <paramref name="timestamp"/>
77+
/// is converted to a <see cref="DateTime"/> in UTC before generating the <see cref="SqlGuid"/>.
78+
/// </remarks>
3679
public static SqlGuid NewSqlGuid(this SequentialSqlGuidGenerator generator, Instant timestamp) =>
3780
generator.NewSqlGuid(timestamp.ToDateTimeUtc());
3881

3982
/// <summary>
40-
/// Will return the value of SystemClock.Instance.GetCurrentInstant() at the time of the generation of the Guid will
41-
/// keep you from needing to store separate audit fields
83+
/// Converts a <see cref="Guid"/> to a <see cref="NodaTime.Instant"/> if the <see cref="Guid"/> contains a valid timestamp.
4284
/// </summary>
43-
/// <param name="id">A sequential Guid with the first 8 bytes containing the system ticks at time of generation</param>
44-
/// <returns>Instant?</returns>
85+
/// <param name="id">The <see cref="Guid"/> to extract the timestamp from.</param>
86+
/// <returns>
87+
/// An <see cref="NodaTime.Instant"/> representing the timestamp embedded in the <see cref="Guid"/>,
88+
/// or <c>null</c> if the <see cref="Guid"/> does not contain a valid timestamp.
89+
/// </returns>
4590
public static Instant? ToInstant(this Guid id) =>
4691
id.ToDateTime().ToInstant();
4792

4893
/// <summary>
49-
/// Will return the value of SystemClock.Instance.GetCurrentInstant() at the time of the generation of the Guid will
50-
/// keep you from needing to store separate audit fields
94+
/// Converts a <see cref="SqlGuid"/> to a nullable <see cref="NodaTime.Instant"/>.
5195
/// </summary>
52-
/// <param name="sqlGuid">
53-
/// A sequential SqlGuid with the first sorted 8 bytes containing the system ticks at time of
54-
/// generation
55-
/// </param>
56-
/// <returns>Instant?</returns>
96+
/// <param name="sqlGuid">The <see cref="SqlGuid"/> to convert.</param>
97+
/// <returns>
98+
/// A nullable <see cref="NodaTime.Instant"/> representing the timestamp embedded in the <see cref="SqlGuid"/>,
99+
/// or <c>null</c> if the <see cref="SqlGuid"/> does not contain a valid timestamp.
100+
/// </returns>
101+
/// <remarks>
102+
/// This method extracts the timestamp from the provided <see cref="SqlGuid"/> and converts it to a
103+
/// <see cref="NodaTime.Instant"/>. If the <see cref="SqlGuid"/> does not contain a valid timestamp,
104+
/// the method returns <c>null</c>.
105+
/// </remarks>
57106
public static Instant? ToInstant(this SqlGuid sqlGuid) =>
58107
sqlGuid.ToDateTime().ToInstant();
59108

60109
// Helper function to prevent code duplication all it does is conditionally convert a nullable datetime to a nullable instant
61110
private static Instant? ToInstant(this DateTime? value) =>
62-
value.HasValue ? Instant.FromDateTimeUtc(value.Value) : default(Instant?);
111+
value.HasValue ? Instant.FromDateTimeUtc(value.Value) : null;
63112
}

src/SequentialGuid/SequentialGuidExtensions.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace System;
88

99
/// <summary>
10-
/// Provides extension methods to return back timestamps from a guid as well as convert to &amp; from normal sorting
11-
/// and SQL Server sorting
10+
/// Provides extension methods for working with <see cref="Guid"/> and <see cref="SqlGuid"/> objects,
11+
/// including conversions and operations related to timestamps and SQL Server sorting order.
1212
/// </summary>
1313
public static class SequentialGuidExtensions
1414
{
@@ -35,11 +35,13 @@ private static DateTime ToDateTime(this long ticks) =>
3535
new(ticks, DateTimeKind.Utc);
3636

3737
/// <summary>
38-
/// Will return the value of DateTime.UtcNow at the time of the generation of the Guid will keep you from storing
39-
/// separate audit fields
38+
/// Converts a <see cref="Guid"/> to a <see cref="DateTime"/> if the <see cref="Guid"/> contains a valid timestamp.
4039
/// </summary>
41-
/// <param name="id">A sequential Guid with the first 8 bytes containing the system ticks at time of generation</param>
42-
/// <returns>DateTime?</returns>
40+
/// <param name="id">The <see cref="Guid"/> to extract the timestamp from.</param>
41+
/// <returns>
42+
/// A <see cref="DateTime"/> representing the timestamp embedded in the <see cref="Guid"/>,
43+
/// or <c>null</c> if the <see cref="Guid"/> does not contain a valid timestamp.
44+
/// </returns>
4345
public static DateTime? ToDateTime(this Guid id)
4446
{
4547
var ticks = id.ToTicks();
@@ -49,26 +51,25 @@ private static DateTime ToDateTime(this long ticks) =>
4951
ticks = new SqlGuid(id).ToGuid().ToTicks();
5052
return ticks.IsDateTime()
5153
? ticks.ToDateTime()
52-
: default(DateTime?);
54+
: null;
5355
}
5456

5557
/// <summary>
56-
/// Will return the value of DateTime.UtcNow at the time of the generation of the Guid will keep you from storing
57-
/// separate audit fields
58+
/// Converts a <see cref="SqlGuid"/> to a <see cref="DateTime"/> if the <see cref="SqlGuid"/> contains a valid timestamp.
5859
/// </summary>
59-
/// <param name="sqlGuid">
60-
/// A sequential SqlGuid with the first sorted 8 bytes containing the system ticks at time of
61-
/// generation
62-
/// </param>
63-
/// <returns>DateTime?</returns>
60+
/// <param name="sqlGuid">The <see cref="SqlGuid"/> to extract the timestamp from.</param>
61+
/// <returns>
62+
/// A <see cref="DateTime"/> representing the timestamp embedded in the <see cref="SqlGuid"/>,
63+
/// or <c>null</c> if the <see cref="SqlGuid"/> does not contain a valid timestamp.
64+
/// </returns>
6465
public static DateTime? ToDateTime(this SqlGuid sqlGuid) =>
6566
sqlGuid.ToGuid().ToDateTime();
6667

6768
/// <summary>
68-
/// Will take a SqlGuid and re-sequence to a Guid that will sort in the same order
69+
/// Converts a <see cref="SqlGuid"/> to a <see cref="Guid"/>.
6970
/// </summary>
70-
/// <param name="sqlGuid">Any SqlGuid</param>
71-
/// <returns>Guid</returns>
71+
/// <param name="sqlGuid">The <see cref="SqlGuid"/> to convert.</param>
72+
/// <returns>A <see cref="Guid"/> representation of the specified <see cref="SqlGuid"/>.</returns>
7273
public static Guid ToGuid(this SqlGuid sqlGuid)
7374
{
7475
var bytes = sqlGuid.ToByteArray()
@@ -80,11 +81,11 @@ public static Guid ToGuid(this SqlGuid sqlGuid)
8081
}
8182

8283
/// <summary>
83-
/// Will take a Guid and will re-sequence it so that it will sort properly in SQL Server without fragmenting your
84-
/// tables
84+
/// Converts a <see cref="Guid"/> to a <see cref="SqlGuid"/> by rearranging its byte order
85+
/// to match the sorting order used by SQL Server.
8586
/// </summary>
86-
/// <param name="id">Any Guid</param>
87-
/// <returns>SqlGuid</returns>
87+
/// <param name="id">The <see cref="Guid"/> to convert.</param>
88+
/// <returns>A <see cref="SqlGuid"/> representation of the provided <see cref="Guid"/>.</returns>
8889
public static SqlGuid ToSqlGuid(this Guid id)
8990
{
9091
var bytes = id.ToByteArray();

src/SequentialGuid/SequentialGuidGenerator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
namespace SequentialGuid;
22

3-
/// <inheritdoc />
3+
/// <summary>
4+
/// Represents a generator for creating sequential <see cref="Guid"/> values.
5+
/// </summary>
6+
/// <remarks>
7+
/// This sealed class inherits from <see cref="SequentialGuidGeneratorBase{T}"/> and provides
8+
/// an implementation for generating sequential GUIDs. Sequential GUIDs are particularly useful
9+
/// in scenarios where GUIDs are used as primary keys in databases, as they can improve indexing
10+
/// performance by reducing fragmentation.
11+
/// </remarks>
412
public sealed class SequentialGuidGenerator : SequentialGuidGeneratorBase<SequentialGuidGenerator>
513
{
614
private SequentialGuidGenerator() { }

0 commit comments

Comments
 (0)