title: How can I pass a property as a delegate?
body: <p>This is a theoretical question, I've already got a solution to my problem that took me down a different path, but I think the question is still potentially interesting.</p>
  
  <p>Can I pass object properties as delegates in the same way I can with methods?  For instance:</p>
  
  <p>Let's say I've got a data reader loaded up with data, and each field's value needs to be passed into properties of differing types having been checked for DBNull.  If attempting to get a single field, I might write something like:</p>
  
  <pre><code>if(!rdr["field1"].Equals(DBNull.Value)) myClass.Property1 = rdr["field1"];
  </code></pre>
  
  <p>But if I've got say 100 fields, that becomes unwieldy very quickly.  There's a couple of ways that a call to do this might look nice:</p>
  
  <pre><code>myClass.Property = GetDefaultOrValue&lt;string&gt;(rdr["field1"]); //Which incidentally is the route I took
  </code></pre>
  
  <p>Which might also look nice as an extension method:</p>
  
  <pre><code>myClass.Property = rdr["field1"].GetDefaultOrValue&lt;string&gt;();
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>SetPropertyFromDbValue&lt;string&gt;(myClass.Property1, rdr["field1"]); //Which is the one that I'm interested in on this theoretical level
  </code></pre>
  
  <p>In the second instance, the property would need to be passed as a delegate in order to set it.</p>
  
  <p>So the question is in two parts:</p>
  
  <ol>
  <li>Is this possible?</li>
  <li>What would that look like?</li>
  </ol>
  
  <p>[As this is only theoretical, answers in VB or C# are equally acceptable to me]</p>
  
  <p><strong>Edit:</strong> There's some slick answers here.  Thanks all.</p>