MailChimp.NET
MailChimp.NET copied to clipboard
Please create default instances for objects
Scenario: I create CampaignSegmentOptions
CampaignSegmentOptions x = new CampaignSegmentOptions(); x.Conditions.Add(some obj); //here I get null object error because Conditions is null
Here is the solution: a public constructor (I will add to my fork)
/// <summary>
/// A list of criteria on which to segment a list
/// </summary>
[DataContract]
public class CampaignSegmentOptions
{
public CampaignSegmentOptions()
{
Conditions = new List<CampaignSegmentCriteria>();
}
/// <summary>
/// Controls whether to use AND or OR when applying your options - expects "any" (for OR) or "all" (for AND)
/// </summary>
[DataMember(Name = "match")]
public string Match { get; set; }
/// <summary>
/// Collection of up to 5 structs for different criteria to apply while segmenting.
/// Each criteria row must contain 3 keys - "field", "op", and "value" - and possibly a fourth, "extra", based on these definitions: http://apidocs.mailchimp.com/api/2.0/campaigns/segment-test.php
/// </summary>
[DataMember(Name = "conditions")]
public List<CampaignSegmentCriteria> Conditions { get; set; }
}
P.S. Would be nice to go over all object and create constructors with default instances, if of course there is no reason not to do so :)
One reason to not do this is, if you convert the object back to json this will result into a empty array instead of null value (resulting in leaving the property out in the result json).
so you talking optimization of the resulting JSON string, usually the focus is on optimization of hours spent on development and decreasing bug possibility, anyhow, I don't care, I wish to be removed from this topic