Skip to content

Commit

Permalink
Add bool to yes/no converter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNDRmac committed Jul 12, 2023
1 parent 986e5d3 commit db4576d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
and this project adheres to [Semantic Versioning](http://semver.org).

## [Unreleased] - TBD
## Added
- Added `DateValidatorTag` to Complex Tags


## [1.2.0] - 2023-07-03
Expand Down
2 changes: 2 additions & 0 deletions SignNow.Net/Model/ComplexTags/DateValidatorTag.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SignNow.Net.Internal.Helpers.Converters;

namespace SignNow.Net.Model.ComplexTags
{
Expand All @@ -16,6 +17,7 @@ public class DateValidatorTag : ComplexTagWithLabel
/// Lock Signing Date option
/// </summary>
[JsonProperty("lsd", Order = 1)]
[JsonConverter(typeof(BoolToStringYNJsonConverter))]
public bool LockSigningDate { get; set; }

[JsonProperty("validator_id", Order = 2)]
Expand Down
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);
}
}
}

0 comments on commit db4576d

Please sign in to comment.