I have a vb.net project that uses an XML literal to configure the user interface navigation bar. The code looks something like this and has been working for many years.
Private ReadOnly _actionTreeXml As XElement =
<nodes>
<node key="any" name="Top">
<node key="log" name="***LOGIN***" type="everybody"></node>
<node key="op" name="Home" ctrl="uiHomePage" type="mfg"></node>
<node key="barcode" name="Barcode Entry" ctrl="EditMfgEntry" type="mfg"></node>
<node key="wip" name="Work in Progress" ctrl="QueryWIP" type="mfg"></node>
<node key="readme" name="Version Info" type="everybody"></node>
</node>
</nodes>
I recently needed to have two builds of the project that differ slightly (don't want to pay for library code for many users). So I have one build where I #if out all the ui tools related to the barcode. This works great everwhere except in XML literals like this
#if USE_BAR_CODE=1
<node key="barcode" name="Barcode Entry" ctrl="EditMfgEntry" type="mfg"> </node>
#end if
If I set USE_BAR_CODE to 0 I still get the xml literal inside the #if block, but everywhere in my code where I #if'ed regular VB source the code was not compiled.
This leads me to believe that the compliation process handles xml literals BEFORE #if statements. Am I missing something?
May be not the solution at all, but as proverb says "A bad bush is better than the open field".
The main idea is to use processing instruction node. If element has processing instruction above it, then skip it, otherwise include it. This way you can control the "inclusiveness" of that element.
1) First, create extension method:
2. Query our XML: