How to correctly parse Dictionary<string, object> into
<p>I was working on <code>HtmlHelper.AnonymousObjectToHtmlAttributes</code>.</p>

<p>It works well with anonymous object:</p>

<pre><code>var test = new {@class = "aaa", placeholder = "bbb"};
var parseTest= HtmlHelper.AnonymousObjectToHtmlAttributes(test);
</code></pre>

<p>The result <code>parseTest</code> has two key-value pairs.</p>

<p>But for <code>Dictionary</code> object:</p>

<pre><code>var attrsInDict = new Dictionary&lt;string,object&gt;() {            
    {"class", "form-control"},
    {"placeholder", "Select one..."}
};
var attrs = HtmlHelper.AnonymousObjectToHtmlAttributes(attrsInDict );
</code></pre>

<p>The <code>attrs</code> obtained is a strange object, with 4 Keys and 4 Values. The 4 keys are <strong>Comparer</strong>, <strong>Count</strong>, <strong>Keys</strong>,<strong>Values</strong>.</p>

<p>Some other SO post asking about the difference between the two(<a href="https://stackoverflow.com/questions/8160275/difference-between-anonymous-class-and-idictionarystring-object-for-htmlattrib">here</a>). The selected answer says</p>

<blockquote>
  <p>There's not too much difference...</p>
</blockquote>

<p>Really? And what is the correct way to parse the <code>attrsInDict</code> and get the same result as the one we get from an anonymous object?</p>

<p>For, I intend to merge attribues in the following code:</p>

<pre><code>var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
foreach (var item in attrs)
{
    if (attr.ContainsKey(item.Key))
    {
        attr[item.Key] = $"{attr[item.Key]} {item.Value}";
    }
    else
    {
        attr.Add(item.Key, item.Value);
    }
}
</code></pre>