PowerCSharp.Compatibility 0.1.0

dotnet add package PowerCSharp.Compatibility --version 0.1.0
                    
NuGet\Install-Package PowerCSharp.Compatibility -Version 0.1.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="PowerCSharp.Compatibility" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PowerCSharp.Compatibility" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PowerCSharp.Compatibility" />
                    
Project file
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 PowerCSharp.Compatibility --version 0.1.0
                    
#r "nuget: PowerCSharp.Compatibility, 0.1.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 PowerCSharp.Compatibility@0.1.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=PowerCSharp.Compatibility&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PowerCSharp.Compatibility&version=0.1.0
                    
Install as a Cake Tool

PowerCSharp.Compatibility

PowerCSharp Banner

PowerCSharp.Compatibility License: MIT NuGet NuGet Downloads

.NET Framework compatibility layer for PowerCSharp - Essential utilities and extensions for legacy .NET Framework applications with System.Web dependencies. This package provides a seamless migration path from .NET Framework to modern .NET while maintaining compatibility with existing PowerCSharp interfaces.

โš ๏ธ .NET Framework Exclusive: This package is specifically designed for .NET Framework applications (4.6.2, 4.7.2, 4.8) and includes System.Web dependencies. For modern .NET applications, use other PowerCSharp packages.

๐Ÿ“ฆ Package Information

  • Package ID: PowerCSharp.Compatibility
  • Version: 0.1.0
  • Target Frameworks: .NET Framework 4.6.2, 4.7.2, 4.8
  • Dependencies:
    • System.Text.Json v10.0.8 (modern JSON handling)
    • System.Web (Framework reference)

๐ŸŽฏ Why PowerCSharp.Compatibility?

.NET Framework Legacy Support

PowerCSharp.Compatibility bridges the gap between modern PowerCSharp utilities and legacy .NET Framework applications, providing:

  • System.Web Integration - URL manipulation and web utilities using System.Web
  • Async-to-Sync Bridging - Safe async operations in synchronous contexts
  • Framework-Specific Validation - Validation helpers compatible with older frameworks
  • Migration Path - Gradual upgrade path from .NET Framework to modern .NET

Key Scenarios

  • ASP.NET Web Forms applications requiring modern utilities
  • MVC 5 projects needing async compatibility
  • Web API applications with System.Web dependencies
  • Legacy enterprise applications gradual modernization

๐Ÿš€ Installation

dotnet add package PowerCSharp.Compatibility

Package Manager Console:

Install-Package PowerCSharp.Compatibility

๐Ÿ“š Available Components

๐Ÿ”ค String Extensions (System.Web)

Enhanced string manipulation with System.Web.HttpUtility integration.

using PowerCSharp.Compatibility.Extensions;

// URL query parameter manipulation
string baseUrl = "https://example.com/search";
var parameters = new Dictionary<string, string>
{
    ["q"] = "csharp tutorial",
    ["page"] = "1",
    ["lang"] = "en"
};

string fullUrl = baseUrl.AppendQueryParameters(parameters);
// Result: "https://example.com/search?q=csharp%20tutorial&page=1&lang=en"

๐Ÿ”„ Async Helper

Safely bridge async operations to synchronous contexts without deadlocks.

using PowerCSharp.Compatibility.Helpers;

// In MVC filters or other synchronous contexts
public class MyMvcFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        // Safely call async methods from sync context
        var result = AsyncHelper.RunSync(() => GetUserDataAsync(filterContext.HttpContext.User));
        
        filterContext.ActionParameters["userData"] = result;
        base.OnActionExecuting(filterContext);
    }
    
    private async Task<UserData> GetUserDataAsync(IPrincipal user)
    {
        // Your async operation here
        return await userService.GetUserAsync(user.Identity.Name);
    }
}

โœ… Validation Utilities

Framework-compatible validation helpers with custom attributes.

using PowerCSharp.Compatibility.Utilities;
using PowerCSharp.Compatibility.Utilities.Attributes;

// Method parameter validation
public void ProcessData([ValidatedNotNull] string input, int count)
{
    if (string.IsNullOrEmpty(input))
        throw new ArgumentException("Input cannot be null or empty");
    
    // Additional validation logic
}

// Validation helper usage
bool isValid = ValidationHelper.IsValidEmail("user@example.com");
bool isNumeric = ValidationHelper.IsNumeric("12345");

๐Ÿ—๏ธ Architecture

Package Structure

PowerCSharp.Compatibility/
โ”œโ”€โ”€ Extensions/
โ”‚   โ””โ”€โ”€ StringExtensions.cs          # System.Web URL utilities
โ”œโ”€โ”€ Helpers/
โ”‚   โ””โ”€โ”€ AsyncHelper.cs               # Async-to-sync bridging
โ””โ”€โ”€ Utilities/
    โ”œโ”€โ”€ Attributes/
    โ”‚   โ””โ”€โ”€ ValidatedNotNullAttribute.cs  # Validation attributes
    โ””โ”€โ”€ ValidationHelper.cs          # Framework-compatible validation

Dependencies

  • System.Web - Core .NET Framework web utilities
  • System.Text.Json - Modern JSON handling (backported)
  • No external dependencies - Pure .NET Framework compatibility

๐Ÿ”„ Migration Scenarios

From .NET Framework to Modern .NET

PowerCSharp.Compatibility provides a smooth migration path:

  1. Phase 1: Add PowerCSharp.Compatibility to existing .NET Framework project
  2. Phase 2: Replace custom utilities with PowerCSharp equivalents
  3. Phase 3: Migrate to modern .NET and switch to other PowerCSharp packages
// Phase 1: .NET Framework with PowerCSharp.Compatibility
using PowerCSharp.Compatibility.Extensions;
string url = oldUrl.AppendQueryParameters(params);

// Phase 3: Modern .NET with PowerCSharp.Extensions  
using PowerCSharp.Extensions;
Uri uri = new Uri(oldUrl).AddParameter("key", "value");

Integration with Existing PowerCSharp Packages

// .NET Framework application
using PowerCSharp.Compatibility.Extensions;      // For System.Web utilities
using PowerCSharp.Compatibility.Helpers;         // For async bridging
using PowerCSharp.Core;                          // Shared interfaces

๐ŸŽฏ Target Framework Compatibility

Framework Version Support Notes
.NET Framework 4.6.2+ โœ… Full Minimum supported version
.NET Framework 4.7.2 โœ… Full Recommended version
.NET Framework 4.8 โœ… Full Latest Framework version
.NET Core Any โŒ No Use PowerCSharp.Extensions instead
.NET 5+ Any โŒ No Use PowerCSharp.Extensions instead
.NET Standard Any โŒ No Use PowerCSharp.Extensions instead

๐Ÿงช Testing

PowerCSharp.Compatibility includes comprehensive unit tests for all target frameworks:

# Test all frameworks
dotnet test src/PowerCSharp.Compatibility.Tests

# Test specific framework
dotnet test src/PowerCSharp.Compatibility.Tests --framework net48

๐Ÿ“– Usage Examples

ASP.NET Web Forms Integration

using PowerCSharp.Compatibility.Extensions;
using PowerCSharp.Compatibility.Helpers;

public partial class SearchPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Build search URL with parameters
            var searchParams = new Dictionary<string, string>
            {
                ["q"] = Request.QueryString["q"] ?? "",
                ["category"] = ddlCategories.SelectedValue,
                ["page"] = "1"
            };
            
            string searchUrl = "~/Search.aspx".AppendQueryParameters(searchParams);
            Response.Redirect(searchUrl);
        }
    }
    
    protected async void btnSearch_Click(object sender, EventArgs e)
    {
        // In Web Forms, you might need to call async from sync
        var results = AsyncHelper.RunSync(() => SearchService.SearchAsync(txtSearch.Text));
        gvResults.DataSource = results;
        gvResults.DataBind();
    }
}

MVC 5 Filter with Async Operations

using PowerCSharp.Compatibility.Helpers;
using System.Web.Mvc;

public class UserAuthorizationFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var user = filterContext.HttpContext.User;
        
        // Safely call async authorization service
        var isAuthorized = AsyncHelper.RunSync(() => 
            AuthorizationService.IsUserAuthorizedAsync(user.Identity.Name));
        
        if (!isAuthorized)
        {
            filterContext.Result = new HttpNotFoundResult();
            return;
        }
        
        base.OnActionExecuting(filterContext);
    }
}

Legacy API Integration

using PowerCSharp.Compatibility.Extensions;
using PowerCSharp.Compatibility.Utilities;

public class LegacyApiService
{
    public string BuildApiUrl(string baseUrl, object parameters)
    {
        var dict = new Dictionary<string, string>();
        
        // Convert object to dictionary
        foreach (var prop in parameters.GetType().GetProperties())
        {
            var value = prop.GetValue(parameters)?.ToString() ?? "";
            if (!string.IsNullOrEmpty(value))
            {
                dict[prop.Name] = value;
            }
        }
        
        return baseUrl.AppendQueryParameters(dict);
    }
    
    public bool ValidateRequest(string request)
    {
        return !string.IsNullOrEmpty(request) && 
               ValidationHelper.IsNumeric(request.Substring(0, 4));
    }
}

โš ๏ธ Important Considerations

Async-to-Sync Usage

  • Use sparingly - Only when absolutely necessary (MVC filters, Web Forms)
  • Avoid deadlocks - AsyncHelper prevents common deadlock scenarios
  • Performance impact - Sync-over-async has performance overhead

System.Web Dependencies

  • Framework exclusive - Requires System.Web assembly
  • IIS hosting - Designed for web applications hosted in IIS
  • No cross-platform - Windows-only due to System.Web

Migration Planning

  • Gradual migration - Use as stepping stone to modern .NET
  • Code compatibility - APIs designed to match modern PowerCSharp packages
  • Testing strategy - Comprehensive test coverage for migration validation

Modern .NET Alternatives

Foundation

๐Ÿ“š Documentation

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guidelines for details.

Development Setup for .NET Framework

  1. Prerequisites: Visual Studio 2019+ with .NET Framework development workload
  2. Clone repository: git clone https://github.com/marioarce/PowerCSharp.git
  3. Navigate to project: cd src/PowerCSharp.Compatibility
  4. Build: dotnet build or open in Visual Studio
  5. Test: dotnet test --framework net48

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ž Support


PowerCSharp.Compatibility - Keeping .NET Framework applications powerful and modern! ๐Ÿš€

โ† Back to Main Documentation

Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.0 122 6/1/2026