Dictionary<string, object> temp = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(ProjectName))
{
temp.Add("ProjectName", ProjectName);
}
if (!string.IsNullOrEmpty(Department))
{
temp.Add("Department", Department);
}
if (Month1>0)
{
temp.Add("Month1", Month1);
}
if (Month2 > 0)
{
temp.Add("Month2", Month2);
}
dynamic obj = new System.Dynamic.ExpandoObject();
foreach (KeyValuePair<string, object> item in temp)
{
((IDictionary<string, object>)obj).Add(item.Key, item.Value);
}
最后obj 就是所要的