Suppose that I have a Class with a multiline string like this:
Public Class HelpSection
' This process name (Example: 'MyProcess.exe')
Public Shared ReadOnly ThisProcess As String =
Process.GetCurrentProcess().MainModule.ModuleName
Public Shared ReadOnly Syntax As String =
<a><![CDATA[
[+] Syntax:
ThisProcess (SWITCH)=(VALUE) (IN FILE)
]]></a>.Value
End Class
And now, when I call the multiline string:
Console.WriteLine(HelpSection4.Syntax)
It will print this:
ThisProcess (SWITCH)=(VALUE) (IN FILE)
But I would like to print automatically the ThisProcess
variable content (the process name) like this:
MyProcess.exe (SWITCH)=(VALUE) (IN FILE)
So how I can manage the CDATA literal to set the variable content dynamically?
Is this possibly?
Maybe a better approach to manage this? (dynamically without hardcoding, keep in mind that it's for generic usage)
UPDATE
I'm trying to reproduce @Dan-o solution but of course in my case don't works because it's a CDATA literal, then how to escape it or do the necessary modifications?:
Dim ProcessName As String = "MyProcess.exe"
Dim Help As XElement =
<Help>
<Process><%= ProcessName %></Process>
<Syntax><a><![CDATA[
[+] Syntax:
<% ProcessName %> (SWITCH)=(VALUE) (IN FILE)
]]></a></Syntax>
</Help>
Console.WriteLine(Help.<Process>.Value)
Console.WriteLine(Help.<Syntax>.Value)
UPDATE 2
In a simple XML file (for example, a .NET code snippet) I use this trick that I've learned time ago to scape a character in a CDATA:
<Literal Editable="false">
<ID>cdataend</ID>
<ToolTip>Part of the CDATA end tag.</ToolTip>
<Default>></Default>
</Literal>
Then I could write the >
illegal character inside, like this:
<Code Language="vb"><a><![CDATA[ something ]]$cdataend$</a>.Value ]]></Code>
The thing is that I don't know if that can help me with the variable issue... just I'm trying to give ideas.