daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Dec 6th, 2016 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. string username;
  2. string password;
  3. string domain;
  4. string location;
  5.    
  6. void AssignValueFromConfigFile()
  7. {
  8.     username = ConfigurationManager.AppSettings["username"];
  9.     if (username == null)
  10.         throw new ValueNotFound("username");
  11.  
  12.     password = ConfigurationManager.AppSettings["password"];
  13. }
  14.    
  15. var values = new Dictionary<string,string>() { {"username",""},{"password",""},{"domain",""},{"location",""}}
  16.  
  17. void AssignValueFromConfigFile()
  18. {
  19.     foreach(var val in values)
  20.     {
  21.         val.Value = ConfigurationManager.AppSettings[val.Key];
  22.         if (val.Value == null)
  23.             throw new ValueNotFound(val.Value);
  24.     }
  25. }
  26.    
  27. void AssignValueFromConfigFile(string name, ref string value) {
  28.     value = ConfigurationManager.AppSettings[name];
  29.     if(value == null) {
  30.         throw new ValueNotFound(name);
  31.     }
  32. }
  33.  
  34.     string username;
  35.     string password;
  36.     string domain;
  37.     string location;
  38.     AssignValueFromConfigFile("username", ref username);
  39.     AssignValueFromConfigFile("password", ref password);
  40.     AssignValueFromConfigFile("domain", ref domain);
  41.     AssignValueFromConfigFile("location", ref location);
  42.    
  43. string AssignValueFromConfigFile(string name) {
  44.     var value = ConfigurationManager.AppSettings[name];
  45.     if(value == null) {
  46.         throw new ValueNotFound(name);
  47.     }
  48.     return value;
  49. }
  50.  
  51.     var username = AssignValueFromConfigFile("username");
  52.     var password = AssignValueFromConfigFile("password");
  53.     var domain = AssignValueFromConfigFile("domain");
  54.     var location = AssignValueFromConfigFile("location");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top