Created
May 12, 2020 23:20
-
-
Save einarwh/edc260ed58992c53b4e9d8916301d1a6 to your computer and use it in GitHub Desktop.
A second variation of the shopping cart DTOs using custom attributes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class ShoppingCart | |
{ | |
public ShoppingCart(string state) | |
{ | |
State = state; | |
} | |
[JsonProperty("_state")] | |
public string State { get; } | |
} | |
class EmptyCart : ShoppingCart | |
{ | |
public EmptyCart() : base("empty") {} | |
} | |
class ActiveCart : ShoppingCart | |
{ | |
public ActiveCart() : base("paid") { } | |
[JsonProperty("unpaidItems")] | |
public Item[] UnpaidItems { get; set; } | |
} | |
class PaidCart : ShoppingCart | |
{ | |
public PaidCart() : base("paid") {} | |
[JsonProperty("paidItems")] | |
public Item[] PaidItems { get; set; } | |
[JsonProperty("payment")] | |
public Money Payment { get; set; } | |
[JsonProperty("timestamp")] | |
public string Timestamp { get; set; } | |
} | |
class Item | |
{ | |
[JsonProperty("id")] | |
public string Id { get; set; } | |
[JsonProperty("title")] | |
public string Title { get; set; } | |
[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] | |
public string Description { get; set; } | |
} | |
class Money | |
{ | |
[JsonProperty("amount")] | |
public double Amount { get; set; } | |
[JsonProperty("currency")] | |
public string Currency { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment