2 // System.Configuration.AppSettingsReader
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
10 using System.Reflection;
11 using System.Collections.Specialized;
13 namespace System.Configuration
15 public class AppSettingsReader
17 NameValueCollection appSettings;
19 public AppSettingsReader ()
21 appSettings = ConfigurationSettings.AppSettings;
24 public object GetValue (string key, Type type)
27 throw new ArgumentNullException ("key");
30 throw new ArgumentNullException ("type");
32 string value = appSettings [key];
34 throw new InvalidOperationException ("'" + key + "' could not be found.");
36 if (type == typeof (string))
39 MethodInfo parse = type.GetMethod ("Parse", new Type [] {typeof (string)});
41 throw new InvalidOperationException ("Type " + type + " does not have a Parse method");
45 result = parse.Invoke (null, new object [] {value});
46 } catch (Exception e) {
47 throw new InvalidOperationException ("Parse error.", e);