dotnet / dotnet/vblang

XML literals Enhancements to be more supportive to Vazor: the built-in VB syntax Razor!

Open
#397 40 comments 7 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

In this proposal https://github.com/aspnet/AspNetCore/issues/8674 (please all VB.NET fans, support it), I suggested to use xml literals to implement ASP.NET MVC razor in VB.NET instead of vbhtml files, like this:
```VB.NET
Friend Class View1
Dim Model As IEnumerable(Of MvcMusicStore.Models.Genre)

Public Sub New(model As IEnumerable(Of MvcMusicStore.Models.Genre))
Me.Model = model
ViewBag.Title = "Store"
End Sub

'ViewBag.Title = "Store"
Public ReadOnly Property Razor
Get
Return _

Browse Genres



Select from <%= Model.Count() %> genres:



    <%= (From genre In Model Select
  • <%= genre.Name %>
  • ) %>


End Get
End Property

End Class
```

In this code, I used LinQ because I need to return a value to be embedded in the xml literal. I tried another way:
```VB.NET


    <%= (Iterator Function()
    For Each genre In Model
    Yield
  • <%= genre.Name %>

  • Next
    End Function)() %>

```

Using inline lambdas like this, makes it possible to evaluate any expression with any VB code we want, but I think this can be simplified and shortened as this:

```VB.NET


    <%= For Each genre In Model
    Yield
  • <%= genre.Name %>

  • Next %>

```

This is more like a vbhtml razor page code!
The suggestion is simply to write any vb.net code directly inside the `<%= %>` marks, and use return or Yield to return the desired value that will be used in the xml literal. Return and Yield here are scoped to the Xml literal, and all what VB.NET needs to do, is to wrap all this inside
```
([Iterator] Function( )

End Function)()
```

Where [Iterator] is added if Yield is used in code.
Another example:
```VB.NET


    <%= Select Case Model.Count
    Case 1
    Return
  • One Item

  • Case 2
    Return
  • Two Items

  • Case Else
    Return
  • Many Items

  • End Select %>

```

Which is a shortcut for:
```VB.NET


    <%= (Function()
    Select Case Model.Count
    Case 1
    Return
  • One Item

  • Case 2
    Return
  • Two Items

  • Case Else
    Return
  • Many Items

  • End Select
    End Function)() %>

```

I hope these proposal are taken seriously. VB.NET is too powerful and has many precious hidden treasures, and it is really unfortunate that MS decided to left VB.NET behind to save some effort and money, while VB.NET could have been saved too much time , effort and money spent to develop Razor syntax, while it is already supported in VB syntax!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.