aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
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)