aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMW2009-02-28 16:13:20 +0000
committerMW2009-02-28 16:13:20 +0000
commit77b70759a69494d0d0cd1b978e8b136298ba8a5a (patch)
tree5719cc2824c224a473696bd885bdc247b9c7e6ef
parentChanged it so only .ini file types are loaded from the (optional) config dire... (diff)
downloadopensim-SC_OLD-77b70759a69494d0d0cd1b978e8b136298ba8a5a.zip
opensim-SC_OLD-77b70759a69494d0d0cd1b978e8b136298ba8a5a.tar.gz
opensim-SC_OLD-77b70759a69494d0d0cd1b978e8b136298ba8a5a.tar.bz2
opensim-SC_OLD-77b70759a69494d0d0cd1b978e8b136298ba8a5a.tar.xz
Copied the Util.ReadSettingsFromIniFile method from the branch to trunk.
-rw-r--r--OpenSim/Framework/Util.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 4fce4ac..a0f3567 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Data; 30using System.Data;
30using System.Globalization; 31using System.Globalization;
31using System.IO; 32using System.IO;
@@ -931,5 +932,65 @@ namespace OpenSim.Framework
931 932
932 return displayConnectionString; 933 return displayConnectionString;
933 } 934 }
935
936 public static T ReadSettingsFromIniFile<T>(IConfig config, T settingsClass)
937 {
938 Type settingsType = settingsClass.GetType();
939
940 FieldInfo[] fieldInfos = settingsType.GetFields();
941 foreach (FieldInfo fieldInfo in fieldInfos)
942 {
943 if (fieldInfo.FieldType == typeof(System.String))
944 {
945 fieldInfo.SetValue(settingsClass, config.Get(fieldInfo.Name, (string)fieldInfo.GetValue(settingsClass)));
946 }
947 else if (fieldInfo.FieldType == typeof(System.Boolean))
948 {
949 fieldInfo.SetValue(settingsClass, config.GetBoolean(fieldInfo.Name, (bool)fieldInfo.GetValue(settingsClass)));
950 }
951 else if (fieldInfo.FieldType == typeof(System.Int32))
952 {
953 fieldInfo.SetValue(settingsClass, config.GetInt(fieldInfo.Name, (int)fieldInfo.GetValue(settingsClass)));
954 }
955 else if (fieldInfo.FieldType == typeof(System.Single))
956 {
957 fieldInfo.SetValue(settingsClass, config.GetFloat(fieldInfo.Name, (float)fieldInfo.GetValue(settingsClass)));
958 }
959 else if (fieldInfo.FieldType == typeof(System.UInt32))
960 {
961 fieldInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(fieldInfo.Name, ((uint)fieldInfo.GetValue(settingsClass)).ToString())));
962 }
963 }
964
965 PropertyInfo[] propertyInfos = settingsType.GetProperties();
966 foreach (PropertyInfo propInfo in propertyInfos)
967 {
968 if ((propInfo.CanRead) && (propInfo.CanWrite))
969 {
970 if (propInfo.PropertyType == typeof(System.String))
971 {
972 propInfo.SetValue(settingsClass, config.Get(propInfo.Name, (string)propInfo.GetValue(settingsClass, null)), null);
973 }
974 else if (propInfo.PropertyType == typeof(System.Boolean))
975 {
976 propInfo.SetValue(settingsClass, config.GetBoolean(propInfo.Name, (bool)propInfo.GetValue(settingsClass, null)), null);
977 }
978 else if (propInfo.PropertyType == typeof(System.Int32))
979 {
980 propInfo.SetValue(settingsClass, config.GetInt(propInfo.Name, (int)propInfo.GetValue(settingsClass, null)), null);
981 }
982 else if (propInfo.PropertyType == typeof(System.Single))
983 {
984 propInfo.SetValue(settingsClass, config.GetFloat(propInfo.Name, (float)propInfo.GetValue(settingsClass, null)), null);
985 }
986 if (propInfo.PropertyType == typeof(System.UInt32))
987 {
988 propInfo.SetValue(settingsClass, System.Convert.ToUInt32(config.Get(propInfo.Name, ((uint)propInfo.GetValue(settingsClass, null)).ToString())), null);
989 }
990 }
991 }
992
993 return settingsClass;
994 }
934 } 995 }
935} 996}