CommunityToolkit / CommunityToolkit/dotnet

Guard for IsNotEmpty(Guid)

Open
#812 2 comments 0 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Overview

There should be `Guard.IsNotEmpty(Guid)` API to Guard against empty guids. With current API's the same guard can be achieved by `Guard.IsTrue(guid != Guid.Empty);`.

### API breakdown

```csharp
namespace CommunityToolkit.Diagnostics;

public static partial class Guard
{
public static void IsNotEmpty([DoesNotReturnIf(Guid.Empty)] Guid value, [CallerArgumentExpression(nameof(memory))] string name = "", string message = "");
}
```

Note that I would also prefer to override the message in many cases, but without actually writing the argument name my self, so making also the `message`, with default value of empty string, but would only use it for the message if not empty (maybe).

### Usage example

public class MyClass
{
private Guid _id;

public MyClass(Guid id)
{
Guard.IsNotEmptyGuid(id);

_id = id;
}
}

### Breaking change?

No

### Alternatives

```csharp
Guard.IsTrue(guid == Guid.Empty);
```

### Additional context

We are working with guids a lot in our project and would like to have cleaner guard for empty guids than `Guard.IsTrue(guid == Guid.Empty);`.

Verifying for empty Guid is pointless to have, so we only need guard for `IsNotEmpty`.

I am new to `Guard` API's, so I might be missing some best practices, but noticed this possible shortcoming in the package immediately when starting to use it in our project. Also searched for Stackoverflow and discussions, but there was no discussion to be found around Guid's and Guard.

### Help us help you

Yes, I'd like to be assigned to work on this item

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.