Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
494688a
strings: add .NET 8 and .NET Standard 2.0 compatibility for regex ope…
marioarce Jun 3, 2026
7d7c090
linq: add .NET Standard 2.0 compatibility for exception handling
marioarce Jun 3, 2026
64d4f86
exceptions: add .NET Standard 2.0 compatibility for message operations
marioarce Jun 3, 2026
06782e8
security: fix string literal compatibility for Base64 operations
marioarce Jun 3, 2026
f1a7c18
http: add media type extension methods for content handling
marioarce Jun 3, 2026
14a41bb
compatibility: add timestamp helper for cross-framework operations
marioarce Jun 3, 2026
b72bed7
compatibility: update project configuration for multi-framework support
marioarce Jun 3, 2026
8bb9cdc
aspnetcore: enhance URI extensions for web application development
marioarce Jun 3, 2026
c0a9e95
types: enhance type system extensions for better reflection support
marioarce Jun 3, 2026
5e8d6c0
extensions: remove deprecated HttpRequestMessageExtensions
marioarce Jun 3, 2026
b98f79c
compatibility: add HTTP extensions for cross-framework support
marioarce Jun 3, 2026
3278625
compatibility: add network extensions for cross-framework support
marioarce Jun 3, 2026
181b984
core: add collection utilities for enhanced data structure operations
marioarce Jun 3, 2026
b152ed2
extensions: add compression utilities for data processing
marioarce Jun 3, 2026
bb81245
refactor: reorganize collection extensions and improve API consistency
marioarce Jun 3, 2026
7204108
refactor: reorganize AspNetCore extensions into Extensions namespace
marioarce Jun 3, 2026
1a7b405
docs: enhance package documentation with recent improvements section
marioarce Jun 3, 2026
636e2d8
refactor: remove AsyncHelper from Compatibility package
marioarce Jun 3, 2026
3667130
feat: add AsyncHelper to Compatibility package (rollback)
marioarce Jun 3, 2026
04dbb84
refactor: improve HttpRequestMessageExtensions with AsyncHelper
marioarce Jun 3, 2026
54b6f96
refactor: update namespace references for collection extensions
marioarce Jun 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ 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.

**Recent Improvements (v0.3.0):**
- **Architectural Refactoring**: Centralized interfaces in PowerCSharp.Core for better separation of concerns
- **Package Separation**: Split ASP.NET Core extensions into dedicated package for cleaner dependencies
- **Enhanced Performance**: Optimized implementations with reduced memory allocations
- **Improved Documentation**: Comprehensive API documentation and usage examples
- **Better Testing**: Expanded test coverage across all packages

## 📦 Packages

PowerCSharp is organized into several focused packages:
Expand All @@ -37,8 +44,10 @@ PowerCSharp follows a clean architectural pattern with **centralized interfaces*

- **All interfaces** are located in `PowerCSharp.Core.Interfaces` namespace
- **All models** are located in `PowerCSharp.Core.Models` namespace
- Clear separation of concerns with proper dependency management
- Consistent namespace organization across the entire ecosystem
- **Clear separation of concerns** with proper dependency management
- **Consistent namespace organization** across the entire ecosystem
- **Modular design** allowing selective package installation
- **Dependency-free core** for maximum compatibility

## 🚀 Installation

Expand Down Expand Up @@ -266,16 +275,19 @@ string random = CryptoHelper.GenerateRandomString(10);

## 🎯 Target Frameworks

- **Modern .NET**: .NET 8.0 with full compatibility
- **Modern .NET**: .NET 8.0 with full compatibility and latest features
- **Cross-platform**: .NET Standard 2.0 (PowerCSharp.Core, Extensions, Helpers, Utilities)
- **.NET Framework**: 4.6.2, 4.7.2, 4.8 (via PowerCSharp.Compatibility package)
- **ASP.NET Core**: .NET 8.0 (PowerCSharp.Extensions.AspNetCore package)
- **Legacy Support**: Seamless migration path from .NET Framework to modern .NET

### 🔧 Recent Updates (v0.3.0)
- **Package Compatibility**: Resolved NuGet package compatibility issues for .NET 8.0
- **Dependency Updates**: Updated Microsoft.Extensions packages to compatible versions
- **Build Improvements**: Enhanced build process and package generation
- **Documentation**: Comprehensive documentation updates and API reference
- **Architectural Refactoring**: Centralized interfaces in PowerCSharp.Core for better maintainability
- **Package Separation**: Split ASP.NET Core extensions into dedicated package for cleaner dependencies
- **Performance Optimization**: Reduced memory allocations and improved execution speed
- **Enhanced Testing**: Expanded unit test coverage across all packages
- **Documentation Overhaul**: Comprehensive API documentation and practical examples
- **Build System**: Improved CI/CD pipeline with automated testing and packaging

## 🧪 Testing

Expand Down
8 changes: 7 additions & 1 deletion docs/PowerCSharp.Compatibility.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# PowerCSharp.Compatibility API Reference

Complete API reference for PowerCSharp.Compatibility - .NET Framework compatibility layer with System.Web dependencies.
Complete API reference for PowerCSharp.Compatibility - .NET Framework compatibility layer with System.Web dependencies. This package provides a seamless migration path from .NET Framework to modern .NET while maintaining compatibility with existing PowerCSharp interfaces.

**Key Features:**
- **System.Web Integration**: URL manipulation and web utilities using System.Web
- **Async-to-Sync Bridging**: Safe async operations in synchronous contexts
- **Migration Path**: Gradual upgrade path from .NET Framework to modern .NET
- **Framework Compatibility**: Designed specifically for .NET Framework applications

> **Target Framework**: .NET Framework 4.6.2, 4.7.2, 4.8
> **Namespace**: `PowerCSharp.Compatibility`
Expand Down
8 changes: 7 additions & 1 deletion docs/PowerCSharp.Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Overview

PowerCSharp.Core serves as the foundational core of the PowerCSharp ecosystem, providing centralized interfaces, models, and base functionality for all PowerCSharp packages.
PowerCSharp.Core serves as the foundational core of the PowerCSharp ecosystem, providing centralized interfaces, models, and base functionality for all PowerCSharp packages. This package has been refactored to provide a clean, dependency-free foundation with improved architectural separation and better maintainability.

**Recent Improvements (v0.3.0):**
- **Centralized Interface Design**: All interfaces now centralized for better consistency
- **Dependency-Free Core**: Removed external dependencies for maximum compatibility
- **Enhanced Architecture**: Improved namespace organization and separation of concerns
- **Better Documentation**: Comprehensive API documentation and usage examples

## Architecture

Expand Down
7 changes: 7 additions & 0 deletions docs/PowerCSharp.Extensions.AspNetCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

PowerCSharp.Extensions.AspNetCore provides ASP.NET Core specific extension methods that require ASP.NET Core dependencies. This package focuses on configuration management, web utilities, and HTTP operations that are specifically designed for modern ASP.NET Core applications.

**Recent Improvements (v0.3.0):**
- **Package Separation**: Extracted from PowerCSharp.Extensions for cleaner dependency management
- **Enhanced Performance**: Optimized HTTP operations and configuration handling
- **Better Integration**: Improved ASP.NET Core dependency injection support
- **Updated Dependencies**: All Microsoft.Extensions packages updated to .NET 8.0 compatible versions
- **Improved Documentation**: Comprehensive usage examples and best practices

## Target Framework

- **.NET 8.0** - Leverages the latest ASP.NET Core features and optimizations
Expand Down
9 changes: 8 additions & 1 deletion docs/PowerCSharp.Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

PowerCSharp.Extensions provides cross-platform extension methods for .NET developers that enhance productivity and simplify common programming tasks. This package contains over 100 extension methods organized into logical categories including strings, collections, LINQ, JSON, XML, objects, types, streams, and exception handling.

**Note:** ASP.NET Core specific extensions (Configuration, HTTP utilities, URI manipulation) are now available in the separate `PowerCSharp.Extensions.AspNetCore` package.
**Note:** ASP.NET Core specific extensions (Configuration, HTTP utilities, URI manipulation) are now available in the separate `PowerCSharp.Extensions.AspNetCore` package for cleaner dependency management.

**Recent Improvements (v0.3.0):**
- **Package Separation**: ASP.NET Core extensions moved to dedicated package
- **Performance Optimization**: Reduced memory allocations and improved execution speed
- **Enhanced Documentation**: Better API documentation with practical examples
- **Improved Testing**: Expanded unit test coverage for all extension methods
- **Better Error Handling**: More robust error handling and edge case coverage

## Architecture

Expand Down
6 changes: 6 additions & 0 deletions docs/PowerCSharp.Helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

PowerCSharp.Helpers provides specialized helper classes for cryptography, JSON operations, and environment management. These focused utilities offer secure and reliable implementations of common programming tasks with comprehensive error handling.

**Recent Improvements (v0.2.0):**
- **Enhanced Security**: Improved cryptographic implementations with better error handling
- **Performance Gains**: Optimized JSON serialization and deserialization
- **Better Documentation**: Comprehensive usage examples and security best practices
- **Environment Support**: Enhanced environment variable management with fallback values

## Architecture

### Design Principles
Expand Down
6 changes: 6 additions & 0 deletions docs/PowerCSharp.Utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

PowerCSharp.Utilities provides essential utility classes and helper methods for common programming tasks including file operations, mathematical computations, and validation. This package focuses on providing reliable, performant, and easy-to-use utilities that enhance developer productivity.

**Recent Improvements (v0.2.0):**
- **Enhanced Validation**: Improved validation utilities with better error messages
- **File Operations**: Safer file handling with automatic directory creation
- **Math Functions**: Enhanced mathematical utilities with edge case protection
- **Better Testing**: Comprehensive unit test coverage for all utility methods

## Architecture

### Design Principles
Expand Down
5 changes: 3 additions & 2 deletions samples/WebSample/Extensions/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using PowerCSharp.Extensions;
using PowerCSharp.Extensions.Strings;
using PowerCSharp.Extensions.AspNetCore.Helpers;
using PowerCSharp.Utilities;
using PowerCSharp.Extensions.Collections;
using PowerCSharp.Extensions.Strings;
using PowerCSharp.Helpers;
using PowerCSharp.Utilities;

namespace WebSample.Extensions;

Expand Down
2 changes: 2 additions & 0 deletions src/PowerCSharp.Compatibility/Helpers/TimestampHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace PowerCSharp.Compatibility.Helpers;

/// <summary>
Expand Down
148 changes: 148 additions & 0 deletions src/PowerCSharp.Compatibility/Http/HttpRequestBaseExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Net.Http;
using System.Web;

namespace PowerCSharp.Compatibility.Http;

/// <summary>
/// Extension methods for HttpRequestBase operations, primarily focused on client IP address extraction.
/// </summary>
public static class HttpRequestBaseExtensions
{
/// <summary>
/// Gets the User's client IP Address from an HttpRequestBase.
/// Handles various proxy scenarios including CloudFlare, X-Forwarded-For, and standard headers.
/// </summary>
/// <param name="request">The HttpRequestBase to extract IP from.</param>
/// <returns>An IP Address; null if error or not found.</returns>
/// <remarks>
/// This method checks multiple sources in order of reliability:
/// 1. Forwarded header (RFC 7239)
/// 2. CloudFlare CF-CONNECTING-IP header
/// 3. X-Forwarded-For header
/// 4. Various server variables for load balancer scenarios
/// 5. UserHostAddress as fallback
/// </remarks>
public static string? GetClientIpAddress(this HttpRequestBase? request)
{
if (request == null)
{
return null;
}

if (request.Headers != null)
{
// Handle standardized 'Forwarded' header, refer https://www.rfc-editor.org/rfc/rfc7239
var forwardedHeader = request.Headers["Forwarded"];

if (!string.IsNullOrEmpty(forwardedHeader))
{
foreach (string segment in forwardedHeader.Split(',')[0].Split(';'))
{
string[] pair = segment
.Trim()
.Split('=');

if (pair.Length == 2 && pair[0].Equals("for", StringComparison.OrdinalIgnoreCase))
{
var result = pair[1].Trim('"');

// IPv6 addresses are always enclosed in square brackets
int left = result.IndexOf('['), right = result.IndexOf(']');

if (left == 0 && right > 0)
{
return result.Substring(1, right - 1);
}

// strip port of IPv4 addresses
int colon = result.IndexOf(':');
if (colon != -1)
{
return result.Substring(0, colon);
}

// this will return IPv4, "unknown", and obfuscated addresses
return result;
}
}
}

// Self-hosting using CloudFlare
if (request.Headers?["CF-CONNECTING-IP"] != null)
{
var result = request.Headers["CF-CONNECTING-IP"]?.ToString();

if (!string.IsNullOrEmpty(result))
{
return result;
}
}

// Handle non-standardized 'X-Forwarded-For' header
var xForwardedFor = request.Headers?["X-Forwarded-For"];

if (!string.IsNullOrEmpty(xForwardedFor))
{
return xForwardedFor?.Split(',')[0];
}
}

if (request.ServerVariables != null)
{
if (request.ServerVariables?["HTTP_X_CLUSTER_CLIENT_IP"] != null)
{
var result = request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]?.ToString();

if (!string.IsNullOrEmpty(result))
{
return result;
}
}

// Sometimes the visitors are behind either a proxy server or a router
// and the standard Request.UserHostAddress only captures the IP address of the proxy server or router.
// When this is the case the user's IP address is then stored in the server variable ("HTTP_X_FORWARDED_FOR").
if (request.ServerVariables?["HTTP_X_FORWARDED_FOR"] != null)
{
var result = request.ServerVariables["HTTP_X_FORWARDED_FOR"]?.ToString();

if (!string.IsNullOrEmpty(result))
{
return result;
}
}

if (request.ServerVariables?["REMOTE_ADDR"] != null)
{
var result = request.ServerVariables["REMOTE_ADDR"]
.Split(',')[0]
.Trim();

if (!string.IsNullOrEmpty(result))
{
return result;
}
}
}

// Then, return the UserHostAddress
return request.UserHostAddress;
}

/// <summary>
/// Gets the HTTP method from an HttpRequestBase as an HttpMethod object.
/// </summary>
/// <param name="request">The HttpRequestBase to get the method from.</param>
/// <returns>An HttpMethod object representing the HTTP method.</returns>
public static HttpMethod Method(this HttpRequestBase? request)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}

var result = new HttpMethod(request.HttpMethod);
return result;
}
}
26 changes: 26 additions & 0 deletions src/PowerCSharp.Compatibility/Http/HttpRequestExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Web;

namespace PowerCSharp.Compatibility.Http;

/// <summary>
/// Extension methods for HttpRequest operations, primarily focused on client IP address extraction.
/// </summary>
public static class HttpRequestExtensions
{
/// <summary>
/// Gets the User's client IP Address from an HttpRequest.
/// Wraps the HttpRequestBase functionality for newer ASP.NET applications.
/// </summary>
/// <param name="request">The HttpRequest to extract IP from.</param>
/// <returns>An IP Address; null if error or not found.</returns>
public static string? GetClientIpAddress(this HttpRequest? request)
{
if (request == null)
{
return null;
}

var httpRequestBase = new HttpRequestWrapper(request);
return httpRequestBase?.GetClientIpAddress();
}
}
Loading
Loading