VOOZH about

URL: https://www.nuget.org/packages/BlazorParameterCastingMagic/

⇱ NuGet Gallery | BlazorParameterCastingMagic 1.2.25121215




👁 Image
BlazorParameterCastingMagic 1.2.25121215

dotnet add package BlazorParameterCastingMagic --version 1.2.25121215
 
 
NuGet\Install-Package BlazorParameterCastingMagic -Version 1.2.25121215
 
 
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="BlazorParameterCastingMagic" Version="1.2.25121215" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorParameterCastingMagic" Version="1.2.25121215" />
 
Directory.Packages.props
<PackageReference Include="BlazorParameterCastingMagic" />
 
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 BlazorParameterCastingMagic --version 1.2.25121215
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BlazorParameterCastingMagic, 1.2.25121215"
 
 
#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 BlazorParameterCastingMagic@1.2.25121215
 
 
#: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=BlazorParameterCastingMagic&version=1.2.25121215
 
Install as a Cake Addin
#tool nuget:?package=BlazorParameterCastingMagic&version=1.2.25121215
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

BlazorParameterCastingMagic

Overview

The BlazorParameterCastingMagic package provides a way to handle dynamic casting of parameters in Blazor components. It is a convenient and flexible way to use implicit casting within your Blazor components to handle parameter values.

Blazor does not natively support implicit conversions for parameters. This means that even if you've defined implicit conversions in your classes, Blazor will not use them when trying to convert values for parameters in your components. This leads to casting exceptions when you try to use different types of values for the parameters.

This package introduces a workaround for this problem. It allows developers to apply dynamic casting to the parameters and bypass the casting exceptions that occur when different types of values are used for parameters. If implicit casting is not possible, the package will attempt to map the types using Nextended.Core.

Installation

Provide instructions for installing your package here.

Usage

Firstly, you need to define the AllowMagicCastingAttribute on the parameters of your components where you want to enable dynamic casting.

[Parameter]
[AllowMagicCasting]
public FlexibleParameter Size { get; set; } = 1;

Then, you need to call the ApplyMagicCasting extension method on the parameters in the SetParametersAsync method of your component.

public override Task SetParametersAsync(ParameterView parameters)
{ 
 return base.SetParametersAsync(parameters.ApplyMagicCasting(this));
}

You can now use different types of values for your parameters without running into casting exceptions.

Example 1

You can use a string value for the parameter in your component.

<MyComponent Size="@("11px")" />

Example 2

You can also use a number value for the parameter in your component.

<MyComponent Size="8" />

Both of these examples will work without throwing a casting exception.

Example with a Custom Class

Here is an example of a custom class FlexibleParameter that you can use with the AllowMagicCastingAttribute:

public class FlexibleParameter
{
 public int IntValue { get; set; }
 public string StringValue { get; set; }

 public static implicit operator FlexibleParameter(int intValue)
 {
 return new FlexibleParameter { IntValue = intValue };
 }

 public static implicit operator FlexibleParameter(string stringValue)
 {
 return new FlexibleParameter { StringValue = stringValue };
 }
}

This class has two properties IntValue and StringValue, and implicit conversion operators for int and string. You can use this class for a parameter in your component and apply the AllowMagicCastingAttribute.

Limitations

The BlazorParameterCastingMagic package uses reflection to handle dynamic casting which can be less performant than direct casting. This should not be an issue unless there is a very large number of parameters.

Conclusion

The BlazorParameterCastingMagic package provides a workaround for the lack of support for implicit conversions in Blazor. With this package, you can avoid casting exceptions and use different types of values for your component parameters.

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BlazorParameterCastingMagic:

Package Downloads
MudBlazor.Extensions

MudBlazor.Extensions is a small extension library for MudBlazor from https://mudblazor.com/

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on BlazorParameterCastingMagic:

Repository Stars
fgilde/MudBlazor.Extensions
MudBlazor.Extensions from https://www.mudex.org is a small extension for MudBlazor from https://mudblazor.com
Version Downloads Last Updated
1.2.25121215 50,545 12/12/2025
1.2.25112218 12,643 11/22/2025
1.2.25111314 708 11/13/2025
1.2.25110914 26,636 11/9/2025
1.2.25102110 7,258 10/21/2025
1.2.23060811 284,971 6/8/2023
1.2.23060721 349 6/7/2023
1.2.23060720 314 6/7/2023