Skip to content

Allow keywords as property names in components #32

Description

@snixtho

Currently if you try to name a property that resembles a C# keyword like "class" or "checked", a syntax error will occur within the template engine.

A potential solution, which keeps the component's interface the same for the users of the component is to prefix variable names with @ behind the scenes when a property is part of a C# keyword. To use the property inside the component, the component author must refer to the component as @Name everywhere.

Example:

<component>
    <property type="string" name="class" /> <!-- define the property like normal, 'class' is a C# keyword -->
    
    <template>
        <label class="{{ @class }}" /> <!-- refer to property 'class' with '@class' -->
    </template>
</component>

Here is a list of all keywords in C#: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/

The contextual keywords will probably work without any special treatment, but might want to fully test that first. I can see contextual keywords being a problem inside expressions where they are actually available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions