diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index aadcdc8..96644ec 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -929,7 +929,25 @@ namespace OpenSim.Framework | |||
929 | /// <returns></returns> | 929 | /// <returns></returns> |
930 | public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections) | 930 | public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections) |
931 | { | 931 | { |
932 | object val = default(T); | 932 | return GetConfigVarFromSections<T>(config, varname, sections, default(T)); |
933 | } | ||
934 | |||
935 | /// <summary> | ||
936 | /// Gets the value of a configuration variable by looking into | ||
937 | /// multiple sections in order. The latter sections overwrite | ||
938 | /// any values previously found. | ||
939 | /// </summary> | ||
940 | /// <remarks> | ||
941 | /// If no value is found then the given default value is returned | ||
942 | /// </remarks> | ||
943 | /// <typeparam name="T">Type of the variable</typeparam> | ||
944 | /// <param name="config">The configuration object</param> | ||
945 | /// <param name="varname">The configuration variable</param> | ||
946 | /// <param name="sections">Ordered sequence of sections to look at</param> | ||
947 | /// <param name="val">Default value</param> | ||
948 | /// <returns></returns> | ||
949 | public static T GetConfigVarFromSections<T>(IConfigSource config, string varname, string[] sections, object val) | ||
950 | { | ||
933 | foreach (string section in sections) | 951 | foreach (string section in sections) |
934 | { | 952 | { |
935 | IConfig cnf = config.Configs[section]; | 953 | IConfig cnf = config.Configs[section]; |
@@ -937,11 +955,7 @@ namespace OpenSim.Framework | |||
937 | continue; | 955 | continue; |
938 | 956 | ||
939 | if (typeof(T) == typeof(String)) | 957 | if (typeof(T) == typeof(String)) |
940 | { | ||
941 | if (val == null) // no null strings, please | ||
942 | val = string.Empty; | ||
943 | val = cnf.GetString(varname, (string)val); | 958 | val = cnf.GetString(varname, (string)val); |
944 | } | ||
945 | else if (typeof(T) == typeof(Boolean)) | 959 | else if (typeof(T) == typeof(Boolean)) |
946 | val = cnf.GetBoolean(varname, (bool)val); | 960 | val = cnf.GetBoolean(varname, (bool)val); |
947 | else if (typeof(T) == typeof(Int32)) | 961 | else if (typeof(T) == typeof(Int32)) |
@@ -949,8 +963,9 @@ namespace OpenSim.Framework | |||
949 | else if (typeof(T) == typeof(float)) | 963 | else if (typeof(T) == typeof(float)) |
950 | val = cnf.GetFloat(varname, (int)val); | 964 | val = cnf.GetFloat(varname, (int)val); |
951 | else | 965 | else |
952 | m_log.WarnFormat("[UTIL]: Unhandled type {0}", typeof(T)); | 966 | m_log.ErrorFormat("[UTIL]: Unhandled type {0}", typeof(T)); |
953 | } | 967 | } |
968 | |||
954 | return (T)val; | 969 | return (T)val; |
955 | } | 970 | } |
956 | 971 | ||