aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorDiva Canto2013-02-22 15:57:33 -0800
committerDiva Canto2013-02-22 15:57:33 -0800
commit0e8289cd002b1947e172d1bfc77fdd0b16d92ffb (patch)
tree5eadc5f0bb6bc6d69c574aeaf46bd4482bab4f0b /OpenSim/Framework/Util.cs
parentErr.. wrong dll name for groups in Robust.HG.ini.example (diff)
downloadopensim-SC_OLD-0e8289cd002b1947e172d1bfc77fdd0b16d92ffb.zip
opensim-SC_OLD-0e8289cd002b1947e172d1bfc77fdd0b16d92ffb.tar.gz
opensim-SC_OLD-0e8289cd002b1947e172d1bfc77fdd0b16d92ffb.tar.bz2
opensim-SC_OLD-0e8289cd002b1947e172d1bfc77fdd0b16d92ffb.tar.xz
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]
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs38
1 files changed, 38 insertions, 0 deletions
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
904 904
905 return val; 905 return val;
906 } 906 }
907
908 /// <summary>
909 /// Gets the value of a configuration variable by looking into
910 /// multiple sections in order. The latter sections overwrite
911 /// any values previously found.
912 /// </summary>
913 /// <typeparam name="T">Type of the variable</typeparam>
914 /// <param name="config">The configuration object</param>
915 /// <param name="varname">The configuration variable</param>
916 /// <param name="sections">Ordered sequence of sections to look at</param>
917 /// <returns></returns>
918 public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections)
919 {
920 object val = default(T);
921 foreach (string section in sections)
922 {
923 IConfig cnf = config.Configs[section];
924 if (cnf == null)
925 continue;
926
927 if (typeof(T) == typeof(String))
928 {
929 if (val == null) // no null strings, please
930 val = string.Empty;
931 val = cnf.GetString(varname, (string)val);
932 }
933 else if (typeof(T) == typeof(Boolean))
934 val = cnf.GetBoolean(varname, (bool)val);
935 else if (typeof(T) == typeof(Int32))
936 val = cnf.GetInt(varname, (int)val);
937 else if (typeof(T) == typeof(float))
938 val = cnf.GetFloat(varname, (int)val);
939 else
940 m_log.WarnFormat("[UTIL]: Unhandled type {0}", typeof(T));
941 }
942 return (T)val;
943 }
944
907 #endregion 945 #endregion
908 946
909 public static float Clip(float x, float min, float max) 947 public static float Clip(float x, float min, float max)