opensim/OpenSim/Framework/Util.cs
/// <summary>
/// Gets the value of a configuration variable by looking into
/// multiple sections in order. The latter sections overwrite 
/// any values previously found.
/// </summary>
/// <remarks>
/// If no value is found then the given default value is returned
/// </remarks>
/// <typeparam name="T">Type of the variable</typeparam>
/// <param name="config">The configuration object</param>
/// <param name="varname">The configuration variable</param>
/// <param name="sections">Ordered sequence of sections to look at</param>
/// <param name="val">Default value</param>
/// <returns></returns>
Gets the value of a configuration variable by looking into
multiple sections in order. The latter sections overwrite
any values previously found.
Gets the value of a configuration variable by looking into multiple sections in order . The latter sections overwrite any values previously found .
public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections, object val)
        {
            foreach (string section in sections)
            {
                IConfig cnf = config.Configs[section];
                if (cnf == null)
                    continue;
                if (typeof(T) == typeof(String))
                    val = cnf.GetString(varname, (string)val);
                else if (typeof(T) == typeof(Boolean))
                    val = cnf.GetBoolean(varname, (bool)val);
                else if (typeof(T) == typeof(Int32))
                    val = cnf.GetInt(varname, (int)val);
                else if (typeof(T) == typeof(float))
                    val = cnf.GetFloat(varname, (float)val);
                else
                    m_log.ErrorFormat("[UTIL]: Unhandled type {0}", typeof(T));
            }
            return (T)val;
        }
public static T GetConfigVarFromSections < T > ( IConfigSource config , string varname , string [ ] sections , object val ) { foreach ( string section in sections ) { IConfig cnf = config . Configs [ section ] ; if ( cnf == null ) continue ; if ( typeof ( T ) == typeof ( String ) ) val = cnf . GetString ( varname , ( string ) val ) ; else if ( typeof ( T ) == typeof ( Boolean ) ) val = cnf . GetBoolean ( varname , ( bool ) val ) ; else if ( typeof ( T ) == typeof ( Int32 ) ) val = cnf . GetInt ( varname , ( int ) val ) ; else if ( typeof ( T ) == typeof ( float ) ) val = cnf . GetFloat ( varname , ( float ) val ) ; else m_log . ErrorFormat ( " " , typeof ( T ) ) ; } return ( T ) val ; }
Gets the value of a configuration variable by looking into
multiple sections in order.
Gets the value of a configuration variable by looking into multiple sections in order .
None
config
IConfigSource
The configuration object
The configuration object
varname
string
The configuration variable
The configuration variable
sections
string[]
Ordered sequence of sections to look at
Ordered sequence of sections to look at
val
object
None
remarks
If no value is found then the given default value is returned
If no value is found then the given default value is returned
typeparam
Type of the variable
Type of the variable