MWTech.Dotnet.Common.Helpers
1.0.0.5
dotnet add package MWTech.Dotnet.Common.Helpers --version 1.0.0.5
NuGet\Install-Package MWTech.Dotnet.Common.Helpers -Version 1.0.0.5
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="MWTech.Dotnet.Common.Helpers" Version="1.0.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MWTech.Dotnet.Common.Helpers" Version="1.0.0.5" />
<PackageReference Include="MWTech.Dotnet.Common.Helpers" />
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 MWTech.Dotnet.Common.Helpers --version 1.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MWTech.Dotnet.Common.Helpers, 1.0.0.5"
#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 MWTech.Dotnet.Common.Helpers@1.0.0.5
#: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=MWTech.Dotnet.Common.Helpers&version=1.0.0.5
#tool nuget:?package=MWTech.Dotnet.Common.Helpers&version=1.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MWTech.Dotnet.Common.Helpers
A comprehensive collection of extension methods and utilities for common .NET operations, providing convenient and reusable functionality across different data types and scenarios.
Features
String Extensions
- Null/whitespace checking
- Case-insensitive comparisons
- MD5 hashing
- File I/O operations
- Safe substring operations
- String truncation with suffix
- Type validation (integer, decimal)
- GUID conversion
Enum Extensions
- Description attribute retrieval
- Display name attribute retrieval
- Enum parsing with defaults
- Selector-friendly string generation
ClaimsPrincipal Extensions
- Claim value retrieval from multiple claim types
- Role checking (any/all roles)
Collection Extensions
- Additional LINQ-style operations for collections
Numeric Extensions
- Utility methods for integers, longs, doubles
File Extensions
- Enhanced file operations
Installation
Copy the Extensions folder and GlobalUsings.cs into your project.
Include the global usings in your project:
// Add to your GlobalUsings.cs or directly in files
global using MWTech.Dotnet.Common.Helpers.Extensions;
Usage Examples
String Extensions
using MWTech.Dotnet.Common.Helpers.Extensions;
string text = "Hello World";
// Check if null or whitespace
bool isEmpty = text.IsNullOrWhitespace();
// Case-insensitive contains
bool contains = text.ContainsIgnoreCase("world");
// Generate MD5 hash
string hash = text.ToMd5Hash();
// Safe substring
string safe = text.SafeSubstring(0, 50);
// Truncate with ellipsis
string truncated = text.Truncate(10); // "Hello Worl…"
// Validate types
bool isInt = "123".IsInteger();
bool isDec = "123.45".IsDecimal();
// Convert to GUID
Guid guid = "550e8400-e29b-41d4-a716-446655440000".ToGuid();
Enum Extensions
public enum Status
{
[Description("Not Started")]
NotStarted,
[Display(Name = "In Progress")]
InProgress
}
Status status = Status.InProgress;
// Get description
string desc = status.GetEnumDescription(); // "In Progress"
// Get display name
string display = status.GetEnumDisplayName(); // "In Progress"
// Parse with default
Status parsed = "notstarted".ToEnum(Status.InProgress); // Status.NotStarted
ClaimsPrincipal Extensions
// In a controller or service
public class MyService
{
private readonly ClaimsPrincipal _user;
public MyService(ClaimsPrincipal user)
{
_user = user;
}
public string GetUserEmail()
{
return _user.GetPropertyValueFromUser("email", "mail", "upn");
}
public bool IsAdminOrManager()
{
return _user.IsInAnyRole("Admin", "Manager");
}
public bool IsSuperUser()
{
return _user.IsInAllRole("Admin", "Manager", "SuperUser");
}
}
Global Usings
The package includes common global usings for convenience:
global using System.ComponentModel;
global using System.Data;
global using System.Reflection;
global using System.Security.Claims;
global using System.Security.Cryptography;
global using System.Text;
Notes
- All extension methods are null-safe where appropriate
- String operations handle edge cases (null, empty, overflow)
- Enum extensions work with Description and Display attributes
- Claims extensions support multiple claim types for flexibility
Dependencies
- System.ComponentModel.DataAnnotations (for Display attribute)
- System.Security.Claims (for ClaimsPrincipal extensions)
License
MIT License
| Product | Versions 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.
-
net10.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.