/[ThermoControl]/trunk/libThermoControl/Configuration.cs
ViewVC logotype

Diff of /trunk/libThermoControl/Configuration.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libThermoControl/Configuration.cs	2014/02/12 03:22:55	28
+++ trunk/libThermoControl/Configuration.cs	2014/02/12 03:28:37	29
@@ -64,13 +64,30 @@
                 var list = o.ToList();
                 if (list.Count == 0)
                 {
-                    Console.WriteLine("Name: '{0}' Default: '{1}' Configured: '{1}'", field.Name, field.GetValue(null).ToString());
+                    var f = field.GetValue(null).ToString();
+                    if (string.IsNullOrEmpty(f)) 
+                    {
+                        throw new ArgumentNullException("f", string.Format("Error - Field: {0} is null or an empty string", field.Name));
+                    }
+                    else
+                    {
+                        Console.WriteLine("Name: '{0}' Default: '{1}' Configured: '{1}'", field.Name, f);
+                    }
                 }
                 else
                 {
                     var t = xdoc.Root.Elements(field.Name).ToList().FirstOrDefault().Value;
-                    Console.WriteLine("Name: '{0}' Default: '{1}' Configured: '{2}'", field.Name, field.GetValue(null).ToString(), t);
-                    field.SetValue(null, Convert.ChangeType(t,field.FieldType));
+                    if (string.IsNullOrEmpty(t))
+                    {
+                        t = field.GetValue(null).ToString();
+                        Console.WriteLine("Name: '{0}' Default: '{1}' Configured: '{2}'", field.Name, t, t);
+                        field.SetValue(null, Convert.ChangeType(t, field.FieldType));
+                    }
+                    else
+                    {
+                        Console.WriteLine("Name: '{0}' Default: '{1}' Configured: '{2}'", field.Name, field.GetValue(null).ToString(), t);
+                        field.SetValue(null, Convert.ChangeType(t, field.FieldType));
+                    }                    
                 }
             }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22