Parsing VB.NET XML Literals

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

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

Is there any way to do this:

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

and so that it evaluates the Integer.MaxValue expression?

+3
source share
3 answers

The short answer is no. The compiler knows how to parse this and replaces your source code with something similar to 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
+2
source

. CodeDOM - - Function Return, Return - ( ), . , .

+1

I think they understand how inline expressions work. I asked this question as a separate question .

0
source

Source: https://habr.com/ru/post/1716937/


All Articles