Bug in XML literals around the Imports keywords..
Posted
Tue, Nov 20 2007 18:22
by
bill
In VB9, there's a bug when using XML literals with any type member that is a protected keyword. For example, given the following psuedo types,
Class Doc
Public Property [Imports]() As List(Of DocImports)
End Class
Class DocImports
Public Property [Namespace]() As String
End Class
The following code won't compile:
Dim d As New Doc
Dim xml = <?xml version="1.0" encoding="utf-8"?>
<Imports>
<%= From item In d.Imports _
Select <Import><Namespace><%= item.Namespace %></Namespace></Import> %>
</Imports>
The trick is to escape the Imports property inside the the XML query:
Dim xml = <?xml version="1.0" encoding="utf-8"?>
<Imports>
<%= From item In d.[Imports] _
Select <Import><Namespace><%= item.Namespace %></Namespace></Import> %>
</Imports>
This seems to only apply to some keywords, not all. Imports, Sub, Function all cause the problem, yet Class, Private and Namespace don't. One thing you'll see is the <%= substitution block won't get the characteristic highlight colour.
And another quirk is if the property is called Option, VB will colour that as if it is a keyword even when it is a property such as stock.Option. This one only seems to impact Option, and does not impact the actual compile, only code aesthetics ;)