Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor] Simplify passing enum values #7466

Closed
1 task done
NUlliiON opened this issue Aug 27, 2022 · 1 comment
Closed
1 task done

[Blazor] Simplify passing enum values #7466

NUlliiON opened this issue Aug 27, 2022 · 1 comment

Comments

@NUlliiON
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Clone of dotnet/aspnetcore#12154
This is a clone of an existing issue. I saw the comment dotnet/aspnetcore#12154 (comment). Is it possible to implement this functionality in the future? This will greatly reduce the amount of code.
My current solution:

public enum StackLayoutHorizontalAlign
{
    Center
}
public enum StackLayoutVerticalAlign
{
    Bottom
}
public class StackLayout : ComponentBase
{
    [Parameter]
    public StackLayoutHorizontalAlign HorizontalAlign { get; set; }

    [Parameter]
    public StackLayoutVerticalAlign VerticalAlign { get; set; }

    ...
}

Usage:

<StackLayout HorizontalAlign="StackLayoutHorizontalAlign.Center" VerticalAlign="StackLayoutVerticalAlign.Bottom">
    ...
</StackLayout>

You could suggest something like:

public class StackLayout : ComponentBase
{
    [Parameter]
    public string HorizontalAlign { get; set; }

    [Parameter]
    public string VerticalAlign { get; set; }

    ...
}

public static class HAlign
{
    public const string Center = "center";

    ...
}

public static class VAlign
{
    public const string Bottom = "bottom";

    ...
}
  1. In this case there is no support for the highlighting code (inconvenient to refactor).
<StackLayout HorizontalAlign="center" VerticalAlign="bottom">
    ...
</StackLayout>
  1. In this case, additional classes complicate the code.
<StackLayout HorizontalAlign="@HAlign.Center" VerticalAlign="VAlign.Bottom">
    ...
</StackLayout>

I don't think this is a solution to the problem.

Describe the solution you'd like

My solution:

public enum StackLayoutHorizontalAlign
{
    Center
}
public enum StackLayoutVerticalAlign
{
    Bottom
}
public class StackLayout : ComponentBase
{
    [Parameter]
    public StackLayoutHorizontalAlign HorizontalAlign { get; set; }

    [Parameter]
    public StackLayoutVerticalAlign VerticalAlign { get; set; }

    ...
}

Usage:

<StackLayout HorizontalAlign="Center" VerticalAlign="Bottom">
    ...
</StackLayout>

I also think that this improvement will work well with "String-based enums" if they are implemented in C# (dotnet/csharplang#2849)

Additional context

No response

@ghost ghost added the untriaged label Oct 29, 2022
@ghost ghost removed the untriaged label Oct 31, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 30, 2022
This issue is being transferred. Timeline may not be complete until it finishes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants