Select a class field by name as though it were a dictionary?
<p>I have a function that filters objects of a specific class by a chosen field. The way I currently do this is that I pass a string naming the field as an argument to the function. Ideally I would want to be able to use this string to select the field in the object, similar to a dictionary (this functionality exists in javascript for example).</p>

<p>So I have the function (cut down to the relevant bits) here:</p>

<pre><code>private List&lt;HangingArtBundle&gt; ConstrainBundlesBy(List&lt;HangingArtBundle&gt; bundles, string valueString, string constraint)
{
    List&lt;HangingArtBundle&gt; retBundles = new List&lt;HangingArtBundle&gt;();
    List&lt;string&gt; values = new List&lt;string&gt;(valueString.Split(new char[] { '|' }));

    foreach (HangingArtBundle bundle in bundles)
    {
        if (values.Contains(ConstrainedField(constraint, bundle)))
        {
            retBundles.Add(bundle);
        }
    }

    return retBundles;
}
</code></pre>

<p>I would like to be able to replace the <code>ConstrainedField(constraint, bundle)</code> part with something like <code>bundle[constraint]</code>, where <code>constraint</code> is the name of a field of the class <code>HangingArtBundle</code>. Instead, I have to use this function below, which requires me to manually add field names as needed:</p>

<pre><code>private string ConstrainedField(string field, HangingArtBundle bundle)
{
    if (field.Equals("Category"))
    {
        return bundle.Category;
    }
    else if (field.Equals("AUToolTab"))
    {
        return bundle.AUToolTab;
    }
    else
    {
        return "";
    }
}
</code></pre>

<p>If it helps at all, here is the class (essentially just a struct):</p>

<pre><code>public class HangingArtBundle
{
    public string CP { get; set; }
    public string Title { get; set; }
    public string Category { get; set; }
    public string AUToolTab { get; set; }
    public List&lt;HangingArtEntry&gt; Art { get; set; }
}
</code></pre>

<p>Is this possible to do in an elegant way in C#?</p>
