我寫了這個功能使用匿名類型代替字典的缺點?
private string BuildXPathQuery(string prefix = "descendant::", string tag = "*", object attrs = null)
{
StringBuilder sb = new StringBuilder(prefix);
sb.Append(tag);
if (attrs != null)
foreach (var a in attrs.GetType().GetProperties())
sb.Append(string.Format("[@{0}='{1}']", a.Name, a.GetValue(attrs, null)));
return sb.ToString();
}
這樣,而不是寫
BuildXPathQuery(attrs: new Dictionary<string,string> {{"attr","value"}});
我可以寫
BuildXPathQuery(attrs: new {attr=value});
但這有什麼缺點?