You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
<propertytype="string"name="class" /> <!-- define the property like normal, 'class' is a C# keyword -->
<template>
<labelclass="{{ @class }}" /> <!-- refer to property 'class' with '@class' -->
</template>
</component>
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.
The text was updated successfully, but these errors were encountered:
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.
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.
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:
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.
The text was updated successfully, but these errors were encountered: