VB2008 : Upcoming features
Just a heads up on one of the new features in VB9 (aka VB.Net 2008) : XML Literals
Quote:
"XML Literals" is the ability to embed XML syntax directly into VB code. For example,
Code:
Dim ele as XElement = <Customer/>
What this means is that you can code your XML (and XLinq) directly in VB and have the compiler worry about all the ghastly DOM navigation that goes on behind the scenes. To see what this means I defer to this excellent example from Beth Massi:
Code:
Private Sub CreateClass()
Dim CustomerSchema As XDocument = XDocument.Load(CurDir() & "\customer.xsd")
Dim fields = From field In CustomerSchema...<xs:element> _
Where field.@type IsNot Nothing _
Select Name = field.@name, Type = field.@type
Dim customer = <customer>
Public Class Customer
<%= From field In fields Select <f>
Private m_<%= field.Name %> As <%= GetVBPropType(field.Type) %></f>.Value %>
<%= From field In fields Select <p>
Public Property <%= field.Name %> As <%= GetVBPropType(field.Type) %>
Get
Return m_<%= field.Name %>
End Get
Set(ByVal value As <%= GetVBPropType(field.Type) %>)
m_<%= field.Name %> = value
End Set
End Property</p>.Value %>
End Class</customer>
My.Computer.FileSystem.WriteAllText("Customer.vb", customer.Value, _
False, System.Text.Encoding.ASCII)
End Sub
Private Function GetVBPropType(ByVal xmlType As String) As String
Select Case xmlType
Case "xs:string"
Return "String"
Case "xs:int"
Return "Integer"
Case "xs:decimal"
Return "Decimal"
Case "xs:boolean"
Return "Boolean"
Case "xs:dateTime", "xs:date"
Return "Date"
Case Else
Return "'TODO: Define Type"
End Select
End Function
Any thoughts?
Re: VB2008 : Upcoming features
To be quite honest, it looks horrible.
Re: VB2008 : Upcoming features
It looks a good deal nicer than the equivalend CodeDom code to generate classes from a XSD would...ufortunately it does bring up bad memories of old stylee ASP...