Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting an XML String into Code in C#
    primarykey
    data
    text
    <p>I have a reporting module in an ASP.NET webforms app (C#) that uses dynamic controls for the parameters for each report.</p> <p>These dynamic controls are built from an XML column in a SQL Server 2008 DB.</p> <p>XML structure:</p> <pre><code>&lt;Report Parameters&gt; &lt;Parameter&gt; &lt;Name&gt;CustomerId&lt;/Name&gt; &lt;Control /&gt; &lt;/Parameter&gt; &lt;Parameter&gt; &lt;Name&gt;Start Date&lt;/Name&gt; &lt;Control&gt;DDL&lt;/Control&gt; &lt;/Parameter&gt; &lt;/Report Parameters&gt; </code></pre> <p>I've left out a lot of the elements for readability. </p> <p>If the <code>&lt;Control&gt;</code> element is not empty (as in the case of the Start Date parameter in the XML example) then a C# based XSLT tranformation creates the appropriate control on my form . </p> <p>If the <code>&lt;Control&gt;</code> element is empty (as in the case of the CustomerId) then I want to use an existing c# property with the same name (i.e. I have a CustomerId defined in my c# code). </p> <p>These parameter values (CustomerId and Start Date) are then passed to a stored procedure used to generate the report data.</p> <p>I use the XPathNavigator and associated classes in my C# code to yank out the <code>&lt;Name&gt;</code> element of any <code>&lt;Control&gt;</code> element that is empty. </p> <p>The problem is that the <code>&lt;Name&gt;</code> element is in the form of a string and I really want it to be in C# code form (sorry can't think of a better way to describe this!) i.e. I want this.CustomerId (added the this to show it's code not a string) not "CustomerId". </p> <p>As I don't know how many reports this system will have over time I don't really want to build up an enum or switch statement if "CustomerId" then this.CustomerId etc. as it seems to negate the point of dynamic code. </p> <p>I realise that reflection will probably be needed and I have little knowledge of this so any advice or advice on a different approach to this problem would be welcome.</p> <p>Thanks,</p> <p>Rich.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload