9

A second variation of the shopping cart DTOs using custom attributes. · GitHub

 3 years ago
source link: https://gist.github.com/einarwh/edc260ed58992c53b4e9d8916301d1a6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
A second variation of the shopping cart DTOs using custom attributes. · GitHub

Instantly share code, notes, and snippets.

A second variation of the shopping cart DTOs using custom attributes.

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; } }


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK