title: Set value of specific property by custom attribute
body: <p>I am currently developing a software that will be used by users that should not be able to access the back-end of it all but should still be able to easily change configuration/settings for the application.
  I decided the best approach would be a custom "configuration file (.cfg)" located in the root of the final build.
  Simple example of the .cfg file:</p>
  
  <pre><code>serveraddress='10.10.10.10'
  serverport='1234'
  servertimeout='15000'
  </code></pre>
  
  <p>Since I wanted the configuration file to easily be extended I decided to use some custom attributes and some simple LINQ.
  This does work like I expect it to, but since I am still a novice in .net I am afraid I have not gone with the best approach and my question is therefor: 
  Is there anything I can do to improve this?
  Or is there just generally a better approach for this?</p>
  
  <p>This is my code for reading the configuration file and assigning the values to it's corresponding properties.</p>
  
  <p>ConfigFileHandler.cs</p>
  
  <pre><code>public void ReadConfigFile()
      {
          var cfgFile = new ConfigFile();
          var configLines = File.ReadAllLines("configfile.cfg");
          var testList = configLines.Select(line =&gt; line.Split('='))
              .Select(splitString =&gt; new Tuple&lt;string, string&gt;(splitString[0], splitString[1].Replace("'", "")))
              .ToList();
          foreach (var prop in typeof(ConfigFile).GetProperties())
          {
              var attrs = (ConfigFileFieldAttribute[])prop.GetCustomAttributes
                  (typeof(ConfigFileFieldAttribute), false);
              foreach (var t in from attr in attrs from t in testList where t.Item1 == attr.Name select t)
              {
                  prop.SetValue(cfgFile, t.Item2);
              }
          }
      }
  </code></pre>
  
  <p>ConfigFile.cs</p>
  
  <pre><code> class ConfigFile
      {
          private static string _serverAddress;
          private static int _serverPort;
          private static int _serverTimeout;
  
          [ConfigFileField(@"serveraddress")]
          public string ServerAddress
          {
              get { return _serverAddress; }
              set { _serverAddress= value; }
          }
  
          [ConfigFileField(@"serverport")]
          public string ServerPort
          {
              get { return _serverPort.ToString(); }
              set { _serverPort= int.Parse(value); }
          }
  
          [ConfigFileField(@"servertimeout")]
          public string ServerTimeout
          {
              get { return _serverTimeout.ToString(); }
              set { _serverTimeout= int.Parse(value); }
          }
      }
  </code></pre>
  
  <p>any tips on writing better looking code would be highly appreciated!</p>
  
  <hr>
  
  <p>UPDATE:
  Thanks for all the feedback.</p>
  
  <p>Below is the final classes!
  <a href="https://dotnetfiddle.net/bPMnJA" rel="nofollow">https://dotnetfiddle.net/bPMnJA</a> for a live example</p>
  
  <p>Please note, this is C# 6.0</p>
  
  <p>ConfigFileHandler.cs</p>
  
  <pre><code> public class ConfigFileHandler
   {
      public void ReadConfigFile()
      {
          var configLines = File.ReadAllLines("configfile.cfg");
          var configDictionary = configLines.Select(line =&gt; line.Split('='))
          .Select(splitString =&gt; new Tuple&lt;string, string&gt;(splitString[0],     splitString[1].Replace("'", "")))
          .ToDictionary(kvp =&gt; kvp.Item1, kvp =&gt; kvp.Item2);
          ConfigFile.SetDictionary(configDictionary);
      }
   }
  </code></pre>
  
  <p>ConfigFile.cs</p>
  
  <pre><code> public class ConfigFile
   {
      private static Dictionary&lt;string, string&gt; _configDictionary;
  
      public string ServerAddress =&gt; PullValueFromConfig&lt;string&gt;("serveraddress", "10.1.1.10");
  
      public int ServerPort =&gt; PullValueFromConfig&lt;int&gt;("serverport", "3306");
  
      public long ServerTimeout =&gt; PullValueFromConfig&lt;long&gt;("servertimeout", "");
  
  
      private static T PullValueFromConfig&lt;T&gt;(string key, string defaultValue)
      {
          string value;
          if (_configDictionary.TryGetValue(key, out value) &amp;&amp; value.Length &gt; 0)
              return (T) Convert.ChangeType(value, typeof (T));
          return (T) Convert.ChangeType(defaultValue, typeof (T));
  
      }
  
      public static void SetDictionary(Dictionary&lt;string, string&gt; configValues)
      {
          _configDictionary = configValues;
      }
   }
  </code></pre>