From e48a8effc31e9dc70492f70eebd4ae3178874aa8 Mon Sep 17 00:00:00 2001 From: Steve Dunn Date: Tue, 16 Jul 2024 08:58:45 +0100 Subject: [PATCH] Update Vogen version and expand FAQ section The Vogen package reference in the ConsumerTests.csproj file was updated to version 4.0.13 from 4.0.4. Additionally, the FAQ.md file under the docs folder was amended to include information on how to use value objects as parameters in Blazor pages and components. The layout of the tutorial "Working-with-Guids.md" in hi.tree was also slightly rearranged. --- docs/site/Writerside/hi.tree | 2 +- docs/site/Writerside/topics/reference/FAQ.md | 26 +++++++++++++++++++- tests/ConsumerTests/ConsumerTests.csproj | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/site/Writerside/hi.tree b/docs/site/Writerside/hi.tree index 2614e3209a..a657b73e4c 100644 --- a/docs/site/Writerside/hi.tree +++ b/docs/site/Writerside/hi.tree @@ -10,7 +10,6 @@ - @@ -19,6 +18,7 @@ + diff --git a/docs/site/Writerside/topics/reference/FAQ.md b/docs/site/Writerside/topics/reference/FAQ.md index 97da354994..b439cc9d9d 100644 --- a/docs/site/Writerside/topics/reference/FAQ.md +++ b/docs/site/Writerside/topics/reference/FAQ.md @@ -502,4 +502,28 @@ public partial struct CustomerId; var newCustomerId = CustomerId.FromNewGuid(); ``` -> To customize the generation of Guids, please see [this tutorial](Working-with-Guids.md) \ No newline at end of file +> To customize the generation of Guids, please see [this tutorial](Working-with-Guids.md) +> + +### Can I use value objects instead of primitives as parameters in Blazor pages and components? + +You can, but it's not straightforward. +Blazor, unlike ASP.NET Core, doesn't consider type converters. +It passes around and stores parameters as objects, +which means that the casting operators in Blazor are also not considered +(it's not possible to have a cast operator that takes `object` in C#). + +There are two solutions: +1. (for components only) - pass the value into the parameter as a value object (parameters can be complex objects) +2. (for pages) override `SetParametersAsync` and convert the primitive to the value object, e.g. + +```c# + public override Task SetParametersAsync(ParameterView parameters) + { + if (parameters.TryGetValue("Id", out var x)) + { + Id = CustomerId.From(x); + } + + ... +``` \ No newline at end of file diff --git a/tests/ConsumerTests/ConsumerTests.csproj b/tests/ConsumerTests/ConsumerTests.csproj index 855fd0cd97..f3d1ca6da7 100644 --- a/tests/ConsumerTests/ConsumerTests.csproj +++ b/tests/ConsumerTests/ConsumerTests.csproj @@ -45,7 +45,7 @@ - +