Access variable based on field in text file, write value to variable based on field in text file
<p>I have a file with values like this:</p>

<pre><code>[Params]
Version=106
Monitor=0
SMode=10000000
Date=20120519
</code></pre>

<p>In my assembly I have properties that correspond to these fields like this:</p>

<pre><code>public static string Version { get; set; }
public static string Monitor { get; set; }
public static string SMode { get; set; }
public static DateTime Date { get; set; }
</code></pre>

<p>I'm iterating through the file like this (_params is a string List with the lines from the [Params] section in the file):</p>

<pre><code>foreach (string s in _params)
{
    string[] values = s.Split('=');

}
</code></pre>

<p>How could I find the variable with values[0] and set it with values[1]?</p>

<p>Edit:</p>

<p>Thanks to Attila, this ended up being my solution. I'm finding the property field by the text in the file, and setting the value from the file. I'm also setting the correct type based on the datatype of the property. I have to do some conversion of some of the strings to make them convert to DateTime datatype:</p>

<pre><code>foreach (string s in _params)
{
    string[] values = s.Split('=');

    object myObject = values[0];
    object myValue = values[1];

    if (myObject.ToString() == "Date")
        myValue = ConvertDateStringToDateTime(values[1]);
    if (myObject.ToString() == "StartTime")
        myValue = ConvertStartTimeStringToDateTime(values[1]);
    if (myObject.ToString() == "Length")
        myValue = ConvertLengthStringToTimeSpan(values[1]);

    var type = typeof(HrmParams);
    var field = type.GetProperty(myObject.ToString());

    myValue = Convert.ChangeType(myValue, field.PropertyType);

    field.SetValue(myObject, myValue, null);            
}
</code></pre>
