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

Allow keywords as property names in components #32

Open
snixtho opened this issue Jul 22, 2023 · 4 comments
Open

Allow keywords as property names in components #32

snixtho opened this issue Jul 22, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@snixtho
Copy link
Member

snixtho commented Jul 22, 2023

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.

@snixtho snixtho added the enhancement New feature or request label Jul 22, 2023
@kdankert
Copy link
Member

Couldn't we internally use @ nanes and add an @ sign to the variables when we resolve double curly braces?

@snixtho
Copy link
Member Author

snixtho commented Jul 22, 2023

Couldn't we internally use @ nanes and add an @ sign to the variables when we resolve double curly braces?

I believe contents within {{ }} is directly evaluated, so that would require a different set up.

@kdankert
Copy link
Member

It won't work for expressions. I would suggest limiting variable names to valid c# variable names then, excluding names beginning with underscores as they are used internally already.

@araszka
Copy link
Member

araszka commented Nov 5, 2023

We could just substitute reserved keywords with something else like var_class. Then in development it would stay class everywhere but the compiled template would have var_class, so for debugging purposes the dev still knows which variable caused a possible issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants