title: Dynamically adding key, value parsed array put into Object.property = value schema
body: <p>I have an object defined as follows:</p>
  
  <pre><code>public class Variable
  {
      public string varName { get; set; }
      public double varVal { get; set; }
      public double varParam { get; set; }
  
      public Variable(string varName1, double varVal1 = 1, double varParam1 = 0)
      {
          varName = varName1;
          varVal = varVal1;
          varParam = varParam1;
      }
  }
  </code></pre>
  
  <p>I have this object in a list that needs to be accessed by many methods in the parent class as follows:</p>
  
  <pre><code>public static List&lt;Variable&gt; variableList = new List&lt;Variable&gt;();
  </code></pre>
  
  <p>I have an input on a text file that I'm using <code>.Split(",")</code> to put into a string array in any order and possibly missing key-values (besides name):</p>
  
  <pre><code>varName,Test,varVal,1.0101,varParam,3.03
  </code></pre>
  
  <p>so in my code, after I use <code>.Split(",")</code> for this text line:</p>
  
  <pre><code>string readKeyvalue[] = { "varName","Test","varVal","1.0101","varParam","3.03" }
  </code></pre>
  
  <p>I must stress that only <code>varName</code> key-pair will be required in the text file, and all of these can be in any order. I want to put them into object properties in the structure like follows (pseudocode):</p>
  
  <pre><code>variableList[0].varName == Test
  variableList[0].varVal == 1.0101
  variableList[0].varParam == 3.03
  </code></pre>
  
  <p>I have failed in my previous efforts to make this possible through sorting the array (which works) and using the following as can be reference in <a href="https://stackoverflow.com/questions/61759917/c-sharp-how-to-use-variables-as-property-names-in-an-object-list-object-construc">my previous question</a>. This line is for the case of a missing <code>varVal</code>, but sorted into a string array of <code>varName,Test,varParam,3.03</code>: </p>
  
  <pre><code>materialList.Add(new Material(sortedVals[1]) { $sortedVals[2] = Convert.ToDouble(sortedVals[3]) } ) ;
  </code></pre>
  
  <p>As you can see, this does not work because <code>sortedVals[2]</code> is not recognized by the compiler as a member declarator, and I can find no way (without 2-3 more classes just for converting the string into a property then brute forcing my way through tons of code) to assign all of the available values to properties while skipping the missing ones.</p>
  
  <p>So to clarify, I can't find a way to assign the available properties to an object while disregarding any missing objects without hardcoding in each and every case (which will be very difficult when I have an object with 10-12 properties).</p>
  
  <p>If anyone has any wisdom, I would be very grateful!</p>