I am writing some custom generic data structures. How can I ensure that the generic type passed in can be serialized by protobuf-net? Since protobuf-net doesn’t rely on interfaces, I can’t constrain the type parameter in that way. I thought about runtime testing of the type inside the constructor, but I can’t even use PrepareSerializer<T> because that relies on the type being a reference type. I could simply attempting a serialization and deserialization, but this seems messy at best. What’s the best way to verify the a given generic type can be serialized?
I am writing some custom generic data structures. How can I ensure that the
Share
XmlProtoSerializer has to make a similar determination. For example:
If that returns a negative value it can’t be serialised. I could make this available in a more supported
bool CanSerialize(Type)if that would be helpful?