<p>I'm currently working on a project where a section of the code looks like this:</p>
<pre><code>Select Case oReader.Name
    Case &quot;NameExample1&quot;
        Me.Elements.NameExample1.Value = oReader.ReadString
        ' ...
    Case &quot;NameExampleN&quot;
        Me.Elements.NameExampleN.Value = oReader.ReadString
        ' ...
End Select
</code></pre>
<p>It continues on for a while. The code is obviously verbose and it <em>feels</em> like it could be improved. Is there any way to dynamically invoke a property in VB.NET such that something like this can be done:</p>
<pre><code>Dim sReadString As String = oReader.ReadString
Me.Elements.InvokeProperty(sReadString).Value = sReadString
</code></pre>

Others have answered perfectly reasonably, but just in case this is a performance-sensitive piece of code, you might want to compile the reflective calls into delegates.
I've got a
blog entry
about turning
MethodBase.Invoke
into delegates. The code is in C#, but the same technique can be applied to VB.NET as well. To use this with properties, get the appropriate "setter" method with
PropertyInfo.GetSetMethod
and then build a delegate which invokes that. You could have a map from field name to "delegate to call to set the field".
Just to reiterate, this is only really necessary if it's in a performance-critical piece of code. Otherwise, you might still want to create a
```
Dictionary<string, PropertyInfo>
```
to avoid calling
```
GetProperty
```
many times, but the step to convert it into a delegate probably isn't worth worrying about.