Skip to content

Strongly typed/type safe passing parameters to components during render and rerender #79

@egil

Description

@egil

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!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is neededinput neededWhen an issue requires input or suggestions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions