-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f9f8c3
commit 32c0e83
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
|
||
namespace BrickOwlSharp.Client.Json | ||
{ | ||
internal class TierPriceListConverter : JsonConverter<List<TierPrice>> | ||
{ | ||
public override List<TierPrice> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var tierPrices = new List<TierPrice>(); | ||
|
||
if (reader.TokenType != JsonTokenType.StartArray) | ||
{ | ||
throw new JsonException(); | ||
} | ||
|
||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType == JsonTokenType.EndArray) | ||
{ | ||
break; | ||
} | ||
|
||
if (reader.TokenType != JsonTokenType.StartArray) | ||
{ | ||
throw new JsonException(); | ||
} | ||
|
||
reader.Read(); | ||
var threshold = reader.GetString(); | ||
reader.Read(); | ||
var price = reader.GetString(); | ||
tierPrices.Add(new TierPrice | ||
{ | ||
Quantity = int.Parse(threshold), | ||
Price = decimal.Parse(price) | ||
}); | ||
|
||
reader.Read(); | ||
if (reader.TokenType != JsonTokenType.EndArray) | ||
{ | ||
throw new JsonException(); | ||
} | ||
} | ||
|
||
return tierPrices; | ||
} | ||
|
||
|
||
public override void Write(Utf8JsonWriter writer, List<TierPrice> value, JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BrickOwlSharp.Client | ||
{ | ||
public class TierPrice | ||
{ | ||
public int Quantity { get; set; } | ||
public decimal Price { get; set; } | ||
} | ||
} |