Search code examples
xmlvb.netxml-literals

VB.NET XML Literals Parsing


If I have a text stored in db, file, resource does not matter:

<code><%= Integer.MaxValue %></code>

Is there a way to do this:

Dim el As XElement = XElement.Parse({variable containing text above})

and to have it evaluate the expression Integer.MaxValue?


Solution

  • Short answer is no. Compiler knows how to parse this and replaces your source code with something that looks like one would do in C# code.

    Test code:

    Dim source As String = "a,s,d,f"
    Dim ar As String() = source.Split(","c)
    Dim el As XElement = <code>
                             <%= From s In ar Select s + "22" %>
                         </code>
    

    Reflected code:

    Dim VB$CG$t_i4$S0 As Integer
    Dim ar As String() = "a,s,d,f".Split(New Char() { ","c })
    Dim VB$t_ref$S0 As New XElement(XName.Get("code", ""))
    VB$t_ref$S0.Add(ar.Select(Of String, String)(New Func(Of String, String)(AddressOf Test._Lambda$__1)))
    Dim el As XElement = VB$t_ref$S0