HelpfulTypesAndExtensions 2.0.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package HelpfulTypesAndExtensions --version 2.0.0
NuGet\Install-Package HelpfulTypesAndExtensions -Version 2.0.0
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="HelpfulTypesAndExtensions" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HelpfulTypesAndExtensions" Version="2.0.0" />
<PackageReference Include="HelpfulTypesAndExtensions" />
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 HelpfulTypesAndExtensions --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HelpfulTypesAndExtensions, 2.0.0"
#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 HelpfulTypesAndExtensions@2.0.0
#: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=HelpfulTypesAndExtensions&version=2.0.0
#tool nuget:?package=HelpfulTypesAndExtensions&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
A collection of useful Interfaces, Base Classes, Utilities, and Extension Methods for .NET
Getting Started 💡
Installation
HelpfulTypesAndExtensionsis available as a NuGet package.- The library targets
.NET Standard 2.0, and.NET 8so it is compatible with a wide range of .NET projects. - The library can be installed with
dotnet add package HelpfulTypesAndExtensionsor via the package manager in your IDE.
Included Types 🎁
Types
TGuid - A Timed Guid
- A Guid that includes a timestamp to allow for sorting and filtering by creation date.
- When created a
TGuidwill have the current tick count appended to it. - The Resulting
TGuidby default will be formatted in the formatGuid-TickCount.
ObservableHashSet<T> - A HashSet that implements INotifyCollectionChanged
- An observable hash set that implements INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
- Exposes events for when items are added, removed, or the entire collection is modified.
ObsverableDictionary<TKey, TValue> - A Dictionary that implements INotifyCollectionChanged
- An observable dictionary that implements INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
- Exposes events for when items are added, removed, or the entire collection is modified.
- Events fire both for Keys and Values.
Enumeration<T> - A record class that represents an enumeration
- Allows for creating enums that can have state and behavior and other typical class features
- Also allows for adding new enumeration values without requiring the typical painful refactoring of existing code
- Performance is faster than a typical enum
- Read more about enumeration classes here and here
Empty - A class that represents an empty value
- Void is not a real type in .NET, it cannot be used as a return type or a variable type
- Many other languages support the concepts of a
Unittype that contains no data - Makes chaining method calls, LINQ queries, and other operations easier where current void methods are used
- Can be used as a return type for methods that do not return a value or to represent a value that is not present
- Can convert a
voidmethod to aFunc<Empty>method to allow for chaining and other operations - Can also convert a
Taskmethod to aTask<Empty>method to allow for chaining and other operations
public Empty DoSomething()
{
var consoleMethod = GetConsoleWrite();
return consoleMethod("Hello World");
}
private Func<string, Empty> GetConsoleWrite()
=> Empty.FromVoidMethod((string message) => Console.WriteLine(message));
BooleanExpression - Wrapper Type for Expressions that return a boolean
- A wrapper type for expressions that return a boolean
- Allows for chaining expressions together and for creating complex boolean expressions
Errors - A collection of classes that represent common error types
- Includes types for
- Client Errors
- Server Errors
- Validation Errors
- Security Errors
- Resource Errors
- Network Errors
- Custom Errors
public class ResultORError<T>
{
public T? Result { get; set; }
public List<IError> Errors { get; set; } = new List<IError>();
}
void Method1()
{
var resultOrError = Method2();
if(resultOrError.Errors.Count > 0)
{
foreach(var error in resultOrError.Errors)
{
Console.WriteLine(error.Message);
}
}
else
{
Console.WriteLine(resultOrError.Result);
}
}
ResultORError<HttpMessage> Method2()
{
HttpClient client = new HttpClient();
var response = client.GetAsync("https://www.google.com").Result;
if(response.IsSuccessStatusCode)
{
return new ResultORError<HttpMessage> { Result = response.Content };
}
else
{
return new ResultORError<HttpMessage> { Errors = [NetworkErrors.ConnectionFailure("Failed to connect to host")] };
}
}
Interfaces
- IDatabaseService
- ISignalRClient
- ISignalRClientModel
- ISignalRHubModel
- IError
Base Classes
- SignalRClient
- SignalRClientModel
Utilities
DebugHelper - A class that provides helper methods that only run in Debug mode
- Provides helper methods that only run in Debug mode using the
DEBUGcompiler directive - Has methods for writing to the console, writing to a file, and customizing the log level
Pathing - A class that provides helper methods for working with file paths
- Provides helper methods for working with file paths
- Has methods for:
- getting the base path of a project
- ensuring a path is formatted corrected to the OS
- Traverse up a directory tree
- If a string exists as a path or not
- Getting a MD5 hash of a file
JSONSerilization - A class that provides helper methods for serializing and deserializing JSON
- Uses the
System.Text.Jsonlibrary to serialize and deserialize JSON - Provides methods for serializing and deserializing objects to and from strings and byte arrays
- Tries to validate and fix the incoming JSON where possible
TryCatch - Provides helper methods for wrapping code in a try-catch blocks
- Provides helper methods for wrapping code in a try-catch block and handling the exceptions
public void DoSomething()
{
TryCatch.Try(() =>
{
// Code that may throw an exception
},
(Exception ex) =>
{
// Handle the exception
});
}
public void DoSomething2()
{
float result = 0;
Func<Exception,float> onError = e =>
{
Console.WriteLine(e.Message); //Prints "Attempted to divide by zero."
return -1;
};
result = TryCatch.Try(() => Divide(1,0), onError);
result.Should().Be(-1); //true
}
Extension Methods
ByteExtensions - Provides extension methods for working with byte arrays
CollectionExtensions - Provides extension methods for working with collections
ConfigurationExtensions - Provides extension methods for working with the IConfiguration in ASP.NET Core
EmptyExtensions - Provides extension methods for working with the Empty class
GenericExtensions - Provides extension methods for working with generic types
StringExtensions - Provides extension methods for working with strings
TaskExtensions - Provides extension methods for working with Tasks
FireAndForget- Allows for a safe way to fire and forget a task in situations where it would otherwise not be possible such as a constructorToEmpty- Converts a Task to an Empty typeIgnoreContext- Sets the task to ignore the current contextWaitAndUnwrapException- Waits for the task to complete and unwraps any exceptions that occur
TGuidExtensions - Provides extension methods for working with TGuids
TypeExtensions - Provides extension methods for working with types
UriExtensions - Provides extension methods for working with URIs
Contributing
Feel free to submit a pull request if you have any useful types or extensions that you would like to add to this library. An ideal contribution is a type or extension that is generally useful across a wide range of projects that you wish were included in .NET by default.
License
HelpfulTypesAndExtensions is licensed under the MIT License (i.e., Fully Open Source) - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 767 | 12/1/2025 |
| 1.9.0 | 261 | 6/29/2025 |
| 1.8.1 | 541 | 6/15/2025 |
| 1.8.0 | 318 | 5/14/2025 |
| 1.7.0 | 207 | 2/25/2025 |
| 1.6.2 | 207 | 11/23/2024 |
| 1.5.0 | 201 | 11/7/2024 |
| 1.4.0 | 252 | 10/19/2024 |
| 1.3.3 | 208 | 10/3/2024 |
| 1.3.2 | 204 | 9/26/2024 |
| 1.3.1 | 196 | 9/25/2024 |
| 1.3.0 | 180 | 9/25/2024 |
| 1.2.1 | 222 | 9/22/2024 |
| 1.2.0 | 184 | 9/20/2024 |
| 1.1.1 | 228 | 9/20/2024 |
| 1.1.0 | 214 | 9/20/2024 |
| 1.0.0 | 214 | 9/19/2024 |