Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If would define the properties that you need this way:</p> <pre><code>&lt;CustomFields&gt; &lt;property name="setting1"&gt;hello&lt;/property&gt; &lt;property name="setting2"&gt;world&lt;/property&gt; ... &lt;/CustomFields&gt; </code></pre> <p>than each "property" becomes child node for CustomFields and your properties are now attributes/values for those child nodes, not attributes of the CustomFields node as in the first example. </p> <p>If you have lot of properties and you want to set them more elegantly here are two options that might consider:</p> <p><strong>1)</strong> Use the following structure for the custom section (slightly changed):</p> <pre><code>&lt;CustomFields&gt; &lt;setting1 value="hello"/&gt; &lt;setting2 value="world"/&gt; ... &lt;/CustomFields&gt; </code></pre> <p>and the following code to define the properties used to retrieve the values:</p> <pre><code>public class CustomFields: ConfigurationSection { [ConfigurationProperty("setting1")] public PropertyElement Setting1 { get { return (PropertyElement)this["setting1"]; } set { this["setting1"] = value; } } [ConfigurationProperty("setting2")] public PropertyElement Setting2 { get { return (PropertyElement)this["setting2"]; } set { this["setting2"] = value; } } } public class PropertyElement : ConfigurationElement { [ConfigurationProperty("value", IsRequired = false)] public String Value { get { return (String)this["value"]; } set { this["value"] = value; } } } </code></pre> <p>Then, to retrieve the values: </p> <pre><code>string setting1value = myCustomFields.Setting1.Value; string setting2value = myCustomFields.Setting2.Value; </code></pre> <p>For details please see <a href="http://msdn.microsoft.com/en-us/library/2tw134k3.aspx" rel="nofollow">How to: Create Custom Configuration Sections Using ConfigurationSection</a> on MSDN.</p> <p><strong>2)</strong> Take a programmatic approach instead of relying on attributes and reflection. <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationsection.aspx" rel="nofollow">ConfigurationSection class</a> or <a href="http://msdn.microsoft.com/en-us/library/ms228056.aspx" rel="nofollow">IConfigurationSectionHandler</a> could be used in this case. As a result you will have access from code to the xml node containing the custom section data and will be able to load any kind of XML structure.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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