public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { IEither either = Activator.CreateInstance(objectType) as IEither; JsonDataType jsonType = Convert(reader.TokenType); EitherTag tag = either.OnDeserializing(jsonType); if (tag == EitherTag.Left) { object left = serializer.Deserialize(reader, either.LeftType); either.Left = left; return(either); } if (tag == EitherTag.Right) { object right = serializer.Deserialize(reader, either.RightType); either.Right = right; return(either); } return(null); }