Proposal: Use <( )> to embed code blocks in XML literals, string literals, and in any expression
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
I suggest to embed VB code blocks in xml literals like this
```VB.NET
Dim x =
<(For i=1 to 10
@i
Next)>
```
I think the `<( )>` is a suitable quote. The <%= %> will continue used to embed values. The `<( )>` will grantee not to break any existing code. It is supposed to return a value, so it is lowered to a function call:
```VB.NET
Dim x =
<(Iterator Function()
For i=1 to 10
Yield
<%= i %>
Next
End Function)( )>
```
Notes:
1. If there is an XElement or a string literal in a separate line inside `<( )>`, implicit return is assumed.
2. If there is an XElement or a string literal inside a loop, implicit Yield is assumed
3. If there is nothing to return or yield in the block, `Return Nothing` is assumed. This will allow writing Subs also to define some variables in the XML literal scope.
4. We can use same Razor `@` rules to switch between text, VB Code, and XML Literals. Again, since the `<( )>` is new quote, there is no fear to break any existing code.
Note that This proposal can be implemented using @AnthonyDGreen 's [Top-Level Code Prototype]( https://anthonydgreen.net/2019/04/23/top-level-code-scenario-a/) can achieve this proposal:
```vb.net
Dim timeOfWeek = <( Select Case Date.Today.DayOfWeek
Case DayOfWeek.Monday To DayOfWeek.Friday
"Work Week"
Case DayOfWeek.Saturday, DayOfWeek.Sunday
"Weekend"
End Select )>
```
and many more, like embedding code in interpolated strings
```vb.net
Dim Msg= $" time Of Week is {<( Select Case Date.Today.DayOfWeek
Case DayOfWeek.Monday To DayOfWeek.Friday
"Work Week"
Case DayOfWeek.Saturday, DayOfWeek.Sunday
"Weekend"
End Select )>}"
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.