-
Notifications
You must be signed in to change notification settings - Fork 12
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
986e5d3
commit db4576d
Showing
3 changed files
with
31 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
27 changes: 27 additions & 0 deletions
27
SignNow.Net/_Internal/Helpers/Converters/BoolToStringYNJsonConverter.cs
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,27 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace SignNow.Net.Internal.Helpers.Converters | ||
{ | ||
/// <summary> | ||
/// Converts <see cref="System.Boolean"/> to <see cref="int"/> | ||
/// </summary> | ||
internal class BoolToStringYNJsonConverter : JsonConverter | ||
{ | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
var toYesNo = (bool)value == true ? "y" : "n"; | ||
writer.WriteValue(toYesNo); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
return reader.Value?.ToString() == "y"; | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(bool); | ||
} | ||
} | ||
} |