I have this method:
private string serializeResult(string errorCode = null, string parameter1 = null, string parameter2 = null, string context = null)
{
return JsonConvert.SerializeObject(new
{
errorCode,
parameter1,
parameter2,
context
});
}
Now if context, errorCode, parameter1 or parameter2 is null, I don't want them to be added for the anonymous type.
How can I do that without testing all kind of options (I have much more parameters, this is a smaller problem)?