C# Conditional Anonymous Object Members in Object initialization
Its not even posibble with codedom or reflection, So you can end up doing if-else if you really need this
if (string.IsNullOrEmpty(cityVal)) {
var obj = new {
Country = countryVal,
Keyword = key,
Page = page
};
// do something
return obj;
} else {
var obj = new {
Country = countryVal,
City = cityVal,
Keyword = key,
Page = page
};
//do something
return obj;
}