HelpfulTypesAndExtensions 1.9.0
dotnet add package HelpfulTypesAndExtensions --version 1.9.0
NuGet\Install-Package HelpfulTypesAndExtensions -Version 1.9.0
<PackageReference Include="HelpfulTypesAndExtensions" Version="1.9.0" />
<PackageVersion Include="HelpfulTypesAndExtensions" Version="1.9.0" />
<PackageReference Include="HelpfulTypesAndExtensions" />
paket add HelpfulTypesAndExtensions --version 1.9.0
#r "nuget: HelpfulTypesAndExtensions, 1.9.0"
#:package HelpfulTypesAndExtensions@1.9.0
#addin nuget:?package=HelpfulTypesAndExtensions&version=1.9.0
#tool nuget:?package=HelpfulTypesAndExtensions&version=1.9.0
A collection of useful Interfaces, Base Classes, Utilities, and Extension Methods for .NET
Getting Started 💡
Installation
HelpfulTypesAndExtensions
is available as a NuGet package.- The library targets
.NET Standard 2.0
, and.NET 8
so it is compatible with a wide range of .NET projects. - The library can be installed with
dotnet add package HelpfulTypesAndExtensions
or 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
TGuid
will have the current tick count appended to it. - The Resulting
TGuid
by 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
Unit
type 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
void
method to aFunc<Empty>
method to allow for chaining and other operations - Can also convert a
Task
method 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
DEBUG
compiler 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.Json
library 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 was computed. 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. |
-
.NETStandard 2.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HelpfulTypesAndExtensions:
Package | Downloads |
---|---|
IntercomEventing
A .NET eventing framework to replace and extend native .NET events. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.9.0 | 146 | 6/29/2025 |
1.8.1 | 200 | 6/15/2025 |
1.8.0 | 225 | 5/14/2025 |
1.7.0 | 109 | 2/25/2025 |
1.6.2 | 112 | 11/23/2024 |
1.5.0 | 111 | 11/7/2024 |
1.4.0 | 164 | 10/19/2024 |
1.3.3 | 124 | 10/3/2024 |
1.3.2 | 120 | 9/26/2024 |
1.3.1 | 112 | 9/25/2024 |
1.3.0 | 98 | 9/25/2024 |
1.2.1 | 124 | 9/22/2024 |
1.2.0 | 92 | 9/20/2024 |
1.1.1 | 131 | 9/20/2024 |
1.1.0 | 131 | 9/20/2024 |
1.0.0 | 124 | 9/19/2024 |