-
-
Notifications
You must be signed in to change notification settings - Fork 119
Strongly typed/type safe passing parameters to components during render and rerender #79
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededinput neededWhen an issue requires input or suggestionsWhen an issue requires input or suggestions
Milestone
Description
Using c# expressions trees to pass parameters to a component during render could make it strongly typed and type safe, avoiding the use of the nameof operator, etc.
The basic idea looks like this:
// MyComponent.razor
@code
{
[Parameter] public string Name { get; set; }
[Parameter] public int Age { get; set; }
}
Test code:
var cut = RenderComponent<MyComponent>(c => c.Name = "asdf", c => c.Age = 42);
I think the signature of RenderComponent then should look like the following... haven't played with expression trees like this before:
T RenderComponent<T>(params Expression<Action<T>>[] parameters)
The RenderComponent method would then translate the expression into a ParameterView with the names and values specified in the lambda.
It would be nice if it was possible to only have to pass one lambda and assign all parameters inside that.
Is this possible? Is it better than the current way to pass parameter?
Input definitely wanted!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededinput neededWhen an issue requires input or suggestionsWhen an issue requires input or suggestions