Results 1 to 3 of 3

Thread: VB2008 : Upcoming features

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    VB2008 : Upcoming features

    Just a heads up on one of the new features in VB9 (aka VB.Net 2008) : XML Literals

    "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?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VB2008 : Upcoming features

    To be quite honest, it looks horrible.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width