Hope I can explain this properly...
I'm building sort of SettingsManager class that keeps track of various settings off the application. I'm aware there are build in stuff for that in C#, but thats not the issue here.
In the XML, I make it simply by constructing the file like this:
<?xml version="1.0" ?>
<setting type="" name="">value</setting>
<setting type="" name="">value</setting>
</xml>
I've designed a class that looks like this:
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Tools.Config
- {
- public class Setting<T>
- {
- #region Constructors
- /// <summary>
- /// Default constructor of the Setting class. Creates a new instance
- /// of the Setting class and initializes the internal fields to the values
- /// provided. The value of the class will be set to the default value of
- /// the specified type.
- /// </summary>
- /// <param name="name">The name of the Setting.</param>
- public Setting(String name)
- : this(name, default(T))
- { }
- /// <summary>
- /// Overloaded constructor of the Setting class. Creates a new instance
- /// of the Setting class and initializes the internal fields to the
- /// values provided.
- /// </summary>
- /// <param name="name">The name of the Setting.</param>
- /// <param name="value">The value of the Setting.</param>
- public Setting(String name, T value)
- {
- Name = name;
- Value = value;
- }
- #endregion
- #region Public Properties
- /// <summary>
- /// Gets or sets the name of the Setting.
- /// </summary>
- public String Name
- {
- get { return m_name; }
- set { m_name = value; }
- }
- /// <summary>
- /// Gets or sets the value of the Setting.
- /// </summary>
- public T Value
- {
- get { return m_value; }
- set { m_value = value; }
- }
- #endregion
- #region Private Fields
- private T m_value; // The value of the setting.
- private String m_name; // The name of the setting.
- #endregion
- }
- }
Now I'm looking for a way that if I read the value of the Type attrbute in a XML document, how I can use that string to do this:
Setting<Type> x = new Setting<Type>(name, value);
where Type is the string value from the type attribute in the XML document.