Enhanced C# extension methods and utilities for .NET developers
PowerCSharp is a comprehensive library of extension methods, utilities, and helper classes designed to enhance your C# development experience. Built by a senior C# architect with 20+ years of experience, this library provides practical, well-tested solutions for common programming challenges.
PowerCSharp is organized into several focused packages:
- PowerCSharp.Core - Core foundation and base classes for PowerCSharp library, including centralized interfaces and models
- PowerCSharp.Extensions - Comprehensive extension methods for collections, HTTP, LINQ, JSON, XML, objects, types, streams, strings, and configuration
- PowerCSharp.Utilities - Utility classes for validation, file operations, and mathematics
- PowerCSharp.Helpers - Specialized helpers for JSON, cryptography, and environment operations
- PowerCSharp.Compatibility - .NET Framework compatibility layer with System.Web dependencies for legacy applications
PowerCSharp follows a clean architectural pattern with centralized interfaces in PowerCSharp.Core:
- All interfaces are located in
PowerCSharp.Core.Interfacesnamespace - All models are located in
PowerCSharp.Core.Modelsnamespace - Clear separation of concerns with proper dependency management
- Consistent namespace organization across the entire ecosystem
Install individual packages via NuGet:
dotnet add package PowerCSharp.Core
dotnet add package PowerCSharp.Extensions
dotnet add package PowerCSharp.Utilities
dotnet add package PowerCSharp.Helpers
dotnet add package PowerCSharp.CompatibilityOr install the complete suite:
dotnet add package PowerCSharp.Core
dotnet add package PowerCSharp.Extensions
dotnet add package PowerCSharp.Utilities
dotnet add package PowerCSharp.Helpers
dotnet add package PowerCSharp.Compatibilityusing PowerCSharp.Extensions;
string text = "hello world";
bool isEmpty = text.IsNullOrWhiteSpace(); // false
string title = text.ToTitleCase(); // "Hello World"
string safe = text.SafeSubstring(0, 5); // "hello"
// Additional string utilities
string camel = "HelloWorld".ToCamelCase(); // "helloWorld"
string firstLower = text.FirstCharToLowerCase(); // "hello world"
string mid = text.Mid(6); // "world"
string normalized = "User Name".NormalizeKey(); // "userName"
string ascii = "cafΓ©".AsAscii(); // "caf"
bool isValid = "https://example.com".IsValidUrl(); // trueusing PowerCSharp.Extensions;
var numbers = new List<int> { 1, 2, 3, 4, 5 };
bool isEmpty = numbers.IsNullOrEmpty(); // false
var first = numbers.FirstOrDefaultSafe(-1); // 1
var page = numbers.Page(1, 2); // [1, 2]
// New collection utilities
var list = new List<string> { "keep", "remove", "keep", "remove" };
int removed = list.RemoveAll(x => x == "remove"); // 2using PowerCSharp.Extensions;
var date = DateTime.Now;
int age = date.GetAge();
bool isWeekend = date.IsWeekend();
var firstDay = date.FirstDayOfMonth();
var lastDay = date.LastDayOfMonth();using PowerCSharp.Extensions;
using System.Net;
// HTTP Status Code utilities
HttpStatusCode status = HttpStatusCode.OK;
bool success = status.IsSuccessful(); // true
bool clientError = status.IsClientError(); // false
bool serverError = status.IsServerError(); // false
bool isRedirect = status.IsRedirect(); // false
// URI manipulation
Uri uri = new Uri("https://example.com");
Uri withParam = uri.AddParameter("search", "test"); // https://example.com?search=test
// HTTP Request cloning
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com");
var clonedRequest = request.Clone();
var clonedAsync = await request.CloneAsync();using PowerCSharp.Extensions;
// Dynamic expression parsing
string expression = "Age > 18 && Name.Contains('John')";
var predicate = expression.GetExpressionDelegate<Person>();
// Dynamic ordering
string orderExpression = "Name DESC, Age ASC";
var orderDelegates = orderExpression.GetOrderDelegates<Person>();
// Dynamic filtering and ordering
var filterProvider = new DynamicFilterProvider<Person>();
var orderProvider = new DynamicOrderProvider<Person>();
var filtered = people.Filter(filterProvider);
var ordered = people.Order(orderProvider);using PowerCSharp.Extensions;
using System.Text.Json;
// JSON element access
JsonElement element = JsonDocument.Parse("{\"name\":\"John\"}").RootElement;
var name = element.Get("name"); // JsonElement with value "John"
var firstItem = element.Get(0); // For arrays
// Case-insensitive JSON access
bool found = element.TryGetPropertyCaseInsensitive("NAME", out var value);
// XML flattening
using System.Xml.Linq;
XElement xml = XElement.Parse("<root><child>value</child></root>");
var dict = xml.Flatten(); // Dictionary with XML structureusing PowerCSharp.Extensions;
// Object utilities
string text = "test";
text.ThrowOnNull(); // Throws if null
bool isTrue = "true".TryGetBool(out bool result); // result = true, isTrue = true
bool isFalse = "0".TryGetBool(out result); // result = false, isFalse = true
// Generic operations
var person = new Person { Name = "John", Age = 30 };
var copy = new Person();
person.CopyPropertiesTo(copy); // Copies matching properties
// Type operations
bool isDefault = default(int).IsDefault(); // true
string typeName = typeof(List<string>).GetGenericTypeName(); // "List<String>"
// Concrete type resolution
Type concreteType = typeof(IMyInterface).GetConcreteType();using PowerCSharp.Extensions;
using var originalStream = new MemoryStream(Encoding.UTF8.GetBytes("test data"));
using var destinationStream = new MemoryStream();
await originalStream.CloneAsync(destinationStream);
// destinationStream now contains the same data as originalStreamusing PowerCSharp.Extensions;
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder().Build();
var options = configuration.GetOptions<MyAppOptions>("MyApp"); // Reads from "MyApp" sectionusing PowerCSharp.Utilities;
bool isValidEmail = ValidationHelper.IsValidEmail("user@example.com");
bool isNumeric = ValidationHelper.IsNumeric("12345");
bool isValidUrl = ValidationHelper.IsValidUrl("https://example.com");using PowerCSharp.Utilities;
string content = FileHelper.SafeReadAllText("file.txt");
bool success = FileHelper.SafeWriteAllText("output.txt", "Hello World");
string size = FileHelper.GetFileSize(1024 * 1024); // "1 MB"using PowerCSharp.Helpers;
var obj = new { Name = "John", Age = 30 };
string json = JsonHelper.SafeSerialize(obj);
var deserialized = JsonHelper.SafeDeserialize<MyClass>(json);
string pretty = JsonHelper.PrettyPrint(json);using PowerCSharp.Helpers;
string sha256 = CryptoHelper.ComputeSHA256("password");
string md5 = CryptoHelper.ComputeMD5("data");
string random = CryptoHelper.GenerateRandomString(10);- Modern .NET: .NET 8.0, .NET Standard 2.0 (compatible with .NET Core 2.0+, .NET 5+)
- .NET Framework: 4.6.2, 4.7.2, 4.8 (via PowerCSharp.Compatibility package)
All PowerCSharp packages include comprehensive unit tests. Run tests with:
dotnet test- PowerCSharp.Core - Core interfaces and architecture
- PowerCSharp.Extensions - Extension methods reference
- PowerCSharp.Utilities - Utility classes guide
- PowerCSharp.Helpers - Specialized helpers reference
- PowerCSharp.Compatibility - .NET Framework compatibility layer
- PowerCSharp.Core API - Complete core API reference
- PowerCSharp.Extensions API - Detailed extensions documentation
- PowerCSharp.Utilities API - Utilities API reference
- PowerCSharp.Helpers API - Helpers API documentation
- PowerCSharp.Compatibility API - .NET Framework compatibility API
- Extensions API Reference - Complete extensions catalog
- Examples and Samples - Working code examples
- Contributing Guide - How to contribute
- Security Policy - Security information
- Code of Conduct - Community guidelines
- Changelog - Version history
- Workflow Documentation - Development workflow
Contributions are welcome! Please read our Contributing Guidelines for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with passion by Mario Arce
- Inspired by 20+ years of C# development experience
- Community feedback and contributions
- π Report Issues
- π‘ Feature Requests
- π§ Email Support
PowerCSharp - Making C# development more powerful, one extension at a time! π
