旧的 Visual Basic 代码在 @ 符号上失败,带有 VBNC30037

Old Visual Basic code fails on @ symbol with VBNC30037

我有很旧的 VB 代码,看起来像这样:

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
    Dim webClient As CookieAwareWebClient = New CookieAwareWebClient()
    Dim result As String
    Dim request As XElement = New XElement("request")
    request.@operation = "UpdateAds"
    For i As Integer = 0 To adsList.Count - 1
        Dim ad As Advertisement = adsList(i)
        Dim adElement As XElement = New XElement("advertisement")
        adElement.@id = ad.id
        adElement.@image_path = ad.image_path
        adElement.@name = ad.name

我正在尝试使用 Xamarin Studio 通过 Mono 编译它。常规 VB 可以正常编译,但是每当 @ 符号出现时我都会得到 error VBNC30037: Symbol is not valid

我不是一个 VB 开发人员,不知道这里的 @ 是什么意思以及为什么它不能编译,因为它曾经在 VB 中编译过.我试过谷歌搜索无济于事。

所以,我想知道我在 Xamarin Studio 中是否做错了什么,或者我是否可以进行一些语法更改以将 @ 替换为可编译的内容。

对于 XML 属性值,此 @ 是 shorthand:

所以你可以重写如下:

原文shorthand:

request.@operation = "UpdateAds"

重写手写:

request.Attribute("operation").Value = "UpdateAds"