I have a type that's
public class Option<T>
{
private bool _hasValue;
private T _value;
private Option(T val) { _value = val; _hasValue = true; }
private Option(bool hasValue) { _hasValue = hasValue; }
public static Option<T> Value(T val) => return new Option(val);
public static Option<T> Nothing() => return new Option(false);
}
I wish I could serialize this using protobuf just like a Nullable<T>
. ie. is there a way to provide protobuf-net with a custom serializer, that would output nothing if _hasValue
is false
and that would output the serialized version of _val
if _hasValue
is true?
Sorry can't seem to find the doc to do this.