BryanCM.AspNet.Utils 1.0.2

dotnet add package BryanCM.AspNet.Utils --version 1.0.2
                    
NuGet\Install-Package BryanCM.AspNet.Utils -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BryanCM.AspNet.Utils" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BryanCM.AspNet.Utils" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="BryanCM.AspNet.Utils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BryanCM.AspNet.Utils --version 1.0.2
                    
#r "nuget: BryanCM.AspNet.Utils, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BryanCM.AspNet.Utils@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BryanCM.AspNet.Utils&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=BryanCM.AspNet.Utils&version=1.0.2
                    
Install as a Cake Tool

BryanCM.AspNet.Utils

This is a project dedicated only to define a set of common functionalities that can be used across multiple projects. These functionalities can be:

  • Definitions of Result Pattern.
  • Abstraction for Error Definitions.
  • Helpers for:
    • Enums (e.g.: for get a Enum's value from a string)
    • JSON Serialization/Deserialization
  • Regex definitions.
  • Injection of Helpers as Services (IServiceCollection).

This project is created as a Package in NuGet and GitHub Packages as BryanCM.AspNet.Utils.

Table of Content

Installation

You can install the package using NuGet. Open the terminal and execute the following command:

dotnet add package BryanCM.AspNet.Utils

Features

Implementation with Enums

Imagine that you're creating an API that has an endpoint that receives a Status Field in its payload. Instead of sending a number value you can receive a string value. But, how can you get the real Enum's value?.

Simple. If you define/declare a Enum like this:

public enum Status
{
    Created,
    InProgress,
    Done
}

... you can use this:

using BryanCM.AspNet.Utils.Helpers;

var statusReceived = "created";
EnumHelper.GetFromString<Status>(statusReceived);

And how can you determine if a value is defined within an Enum?, just do the following putting all together:

using BryanCM.AspNet.Utils.Helpers;

var statusReceived = "created";
if (!EnumHelper.IsInEnumNames<Status>(statusReceived)) { // Verification of Existence
    return;
}

var status = EnumHelper.GetFromString<Status>(statusReceived);

Definition of Errors

You can define your own errors using an Abstract Class as the Base:

using BryanCM.AspNet.Utils.Abstractions

public sealed static class PersonErrors : BaseErrors
{
    private static readonly string _scope = "Person";

    public static readonly Error NotFound = GetError(_scope, nameof(NotFound), "Person not found.");
}

Usage of Result Pattern

In case of Success
using BryanCM.AspNet.Utils.Abstractions;

class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

Result.Success(); // Only to specify a case of success
Result<Person>.Success(new Person{
    Name = "Bryan Carrera",
    Age = 23
}); // To specify a case of success with data as the operation's outcome.
In case of Failure
using BryanCM.AspNet.Utils.Abstractions;

class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

Result.Failure(PersonErrors.NotFound); // or 👇
Result<Person>.Failure(PersonErrors.NotFound);

Usage of Regex

using BryanCM.AspNet.Utils.Regex;

var email = "john.doe@example.com";

if (RegexPatterns.EmailAddress.IsMatch(email))
{
    Console.WriteLine("[x]. Valid");
    return;
}

Console.WriteLine("[x]. Invalid");

Contribution

Contributions are welcome! Please fork the repository and submit a pull request.

Tests

This project uses xUnit for Unit Tests.

To run the tests:

cd src\BryanCM.AspNet.Utils\Tests
dotnet tests
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BryanCM.AspNet.Utils:

Package Downloads
Security.Authz.Api

.NET Package that allows developers configure Authorization in a fast way only providing the Identity Provider to use.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 161 12/29/2025
1.0.1 116 12/29/2025