Printing DisplayName in C#
<p>I have a class Status that has a couple of properties: </p>

<pre><code>Public Class Status 
{
        [DisplayName("Power"), Description("Index 4: transmit power in dBm")]
        public double PwrdBby10
        {
            get { return (_arrayValue[4] / 10.0); }
        }

        [DisplayName("Turbo"), Description("Index 5: transmit turbo size and encoding rate")]
        public string TurboMsgType
        {
            get { return GetEnumString(_arrayValue[5], _elements); }
        }
}
</code></pre>

<p>and I have a reflection function that will compare 2 objects of the same class and print the different properties. </p>

<pre><code> public string Compare(object object1, object object2)
    {
        var source = object1.GetType();
        var propertyNames = source.GetProperties();
        var s = new StringBuilder();

        foreach (var propertyName in propertyNames)
        {
            var propertyValue1 = propertyName.GetValue(object1, null);
            var propertyValue2 = propertyName.GetValue(object2, null);
            if (propertyValue1.ToString() != propertyValue2.ToString())
            {
                if (s.Length &gt; 0)
                    s.Append(", ");
                s.Append(propertyName.Name);
                s.Append("=");
                s.Append(propertyValue2.ToString());
            }
        }
        return s.ToString();
    }
</code></pre>

<p>When I get the result I get the name of the property like <code>"PwrdBpy10 = value"</code>; instead I want the <code>displayName</code> to be printed: <code>"Power = value"</code>.</p>

<p>Can you explain how I can get it to work?</p>
