From 0e8289cd002b1947e172d1bfc77fdd0b16d92ffb Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Fri, 22 Feb 2013 15:57:33 -0800
Subject: 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]
---
OpenSim/Framework/Util.cs | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 1700d3e..8b8e507 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -904,6 +904,44 @@ namespace OpenSim.Framework
return val;
}
+
+ ///
+ /// Gets the value of a configuration variable by looking into
+ /// multiple sections in order. The latter sections overwrite
+ /// any values previously found.
+ ///
+ /// Type of the variable
+ /// The configuration object
+ /// The configuration variable
+ /// Ordered sequence of sections to look at
+ ///
+ public static T GetConfigVarFromSections(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)
--
cgit v1.1