Skip to content

Instantly share code, notes, and snippets.

@michael-wolfenden
Created October 13, 2018 08:51
Show Gist options
  • Save michael-wolfenden/e3c26a5739d38b6852362f0673190b56 to your computer and use it in GitHub Desktop.
Save michael-wolfenden/e3c26a5739d38b6852362f0673190b56 to your computer and use it in GitHub Desktop.
Serialize Lefts
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
using LanguageExt;
using static LanguageExt.Prelude;
using Newtonsoft.Json;
public class Error : NewType<Error, string>
{
public Error(string value) : base(value) { }
}
var toSerialize = Left<Error, int>(Error.New("some error"));
var json = JsonConvert.SerializeObject(toSerialize);
var deserialized = JsonConvert.DeserializeObject(json, typeof(Either<Error, int>));
json.PrintDump();
deserialized.PrintDump();
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ServiceStack.Text" version="5.2.0" targetFramework="net45" />
<package id="LanguageExt.Core" version="3.0.24" targetFramework="net45" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment