Added new Util function for reading config vars that's more generic than the one I added yesterday -- this is for helping move config vars out of [Startup]

This commit is contained in:
Diva Canto
2013-02-22 15:57:33 -08:00
parent 0d08f81421
commit 0e8289cd00
13 changed files with 54 additions and 15 deletions

View File

@@ -904,6 +904,44 @@ namespace OpenSim.Framework
return val;
}
/// <summary>
/// Gets the value of a configuration variable by looking into
/// multiple sections in order. The latter sections overwrite
/// any values previously found.
/// </summary>
/// <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>
/// <returns></returns>
public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections)
{
object val = default(T);
foreach (string section in sections)
{
IConfig cnf = config.Configs[section];
if (cnf == null)
continue;
if (typeof(T) == typeof(String))
{
if (val == null) // no null strings, please
val = string.Empty;
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, (int)val);
else
m_log.WarnFormat("[UTIL]: Unhandled type {0}", typeof(T));
}
return (T)val;
}
#endregion
public static float Clip(float x, float min, float max)