ordercloud-api / headstart

A complete and opinionated eCommerce solution using OrderCloud as the backbone - built with .NET Core and Angular
MIT License
31 stars 74 forks source link

Convert all xp classes into partials #432

Open ajsuth opened 2 years ago

ajsuth commented 2 years ago

To minimise null value bloat stored in xp of OrderCloud resources, we can update the strongly-typed xp classes to inherit from the OrderCloudModel and IPartial, which will remove unassigned properties during serialisation.

See the following example

// Before refactor
public class MyProductXp
{
    public string Note { get; set; }
    public string ProductType { get; set; }
    public bool IsNew { get; set; }
    public decimal Rating { get; set; }
}

// After refactor
public class MyProductXp : OrderCloudModel, IPartial
{
    public string Note { get => GetProp<string>("Note"); set => SetProp<string>("Note", value); }
    public string ProductType { get => GetProp<string>("ProductType"); set => SetProp<string>("ProductType", value); }
    public bool IsNew { get => GetProp<bool>("IsNew"); set => SetProp<bool>("IsNew", value); }
    public decimal Rating { get => GetProp<decimal>("Rating"); set => SetProp<decimal>("Rating", value); }
}