-
Notifications
You must be signed in to change notification settings - Fork 196
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
Improve string handling support #7084
Comments
Raw string literals would be really useful for including code snippets in Blazor pages, currently you have to use verbatim strings and excape all " while also making sure indentation matches. |
This is really annoying, I expect C# features to work in razor files and don't want to keep track of what features aren't implemented, like raw string literals. Please update soon! |
Do we have an update on this? Would be nice if this could make it in .NET 8 GA release. |
Any news on this? |
My current workaround for this issue (raw string literals) is to
This, however, adds more clutter to an existing project when all I need is a tiny file for a simple component... |
This is unacceptable for my use case. The whole point of passing raw string literals as arguments to a component is readability, the fact that I can read the cshtml top to bottom and see the entire content. At that point I might just as well use regular verbatim strings and escape everything. |
@V0ldek @achselschweisz @JohnyL @lofcz @TimPurdum @333fred You can use string literals in your razor (.Net 7) - see below: @{
string literal = $@"""Value {Value}""";
<div>@literal</div>
} or, you can inline it: @{<div>@($@"""Value {Value}""")</div>} Here is another working example: @{<pre>@(@"
{
""Id"": null,
""FName"": ""create"",
""LName"": ""Denny"",
""DateofJoining"": null,
""Date"": ""2023-08-01T00:00:00"",
""CreatedBy"": ""ICC0000389"",
""levels"": {
""RoleId"": ""0"",
""RoleName"": ""select"",
""IsActive"": false,
""CreatedDate"": null,
""CreatedBy"": ""Admin""
},
""functionalities"": [{
""levelID"": 0,
""levelName"": ""create""
}
],
""functionalityList"": []
}")</pre>} It may not be ideal, however, it's an extra 3 characters for a working solution until a better solution is available. However, this fails: @{<pre>@($$"""
{
"Id": null,
"FName": "create",
"LName": "Denny",
"DateofJoining": null,
"Date": "2023-08-01T00:00:00",
"CreatedBy": "ICC0000389",
"levels": {
"RoleId": "0",
"RoleName": "select",
"IsActive": false,
"CreatedDate": null,
"CreatedBy": "Admin"
},
"functionalities": [{
"levelID": 0,
"levelName": "create"
}
],
"functionalityList": []
}
"""
)</pre>} with the following compile error:
|
@gragra33 I think we all want raw string literals spread over several lines to work in razor components. All workarounds, including the one I posted myself, are basically suboptimal. |
@achselschweisz I don't disagree however, for now, there is a working solution. |
Depends on what you mean by "solution". The problem here is that we want raw string literals, which are only materially different from other string tokens when they're multiline. Your comment is basically "but you can use normal strings just fine". Sure, not what we're asking for, though. |
Is there any idea on when this might be implemented? When this issue was opened the feature was still only in preview/rc .NET builds but we're fast approaching the 1-year mark of this feature being in the official latest .NET release. It would be great to have this available for razor files particularly for Blazor development |
I'm wondering if this is related to dotnet/aspnetcore#4976 - String interpolation with nested quotes breaks Razor blocks. |
Correct. When we start taking advantage of Roslyn's lexer in Razor, that issue should also be resolved. I know you all have been patiently waiting for progress here, and this is next on my list of issues to work on. I don't realistically expect that I'll get it in for 17.10, but we know how we're going to approach this now and I expect that it'll be in 17.11. |
When you star with Roslyn's lexer, will this also solve the problem that I cannot use underscores in numbers? |
Yes. My prototype also supports binary literals as well. |
Looks like this issue is finally being resolved! Is there a release soon that this fix will be tied to? |
We expect that you'll be able to opt-in to the new lexer during the initial 9.0 release. Based on feedback from that, we'll look at turning it on by default in a later SDK minor update. |
This is an opt-in feature. You need to add something like |
@jjonescz I've added this line, but still same error. |
Sorry @JohnyL, it looks like the PR adding the new tokenizer didn't make it into .NET 9.0.1xx SDK, you could try a (not officially released) 9.0.2xx SDK from https://github.com/dotnet/sdk/blob/main/documentation/package-table.md |
We will be posting a blog about this change and documenting how to enable it for testing soon; as Jan said, it didn't quite make 9.0.1xx, but will be available in 9.0.2xx. It'll be off by default first, as it's a large change and we want to make sure that it's working well for all users before turning it on by default. |
@jjonescz can this |
Certainly. |
@jjonescz Thanks for a tip! Still doesn't work: |
@JohnyL you will need VS 17.13p2 to see it live in the ide. |
@333fred Beg your pardon, but does such version exists for now? I've got 17.12.p5. |
Not yet, no. As I said, we'll have a blog post out with instructions on how to try it out when it's available. |
Building the solution or running |
There are a few issues around strings in the razor compiler currently:
"
characters in interpolation holes are not handled correctly./cc @DamianEdwards.
The text was updated successfully, but these errors were encountered: