I'm trying to serialize some typesafe enums which I implemented like the answer to this question. When I serialize an object containing a reference to, say, FORMS
(from the answer I linked), I'd like, upon deserialization, to restore the reference to the static field FORMS
.
I have a solution but it seems kind crappy since I'd have to add it to any class that contained a typesafe enum. It pretty much just uses callbacks to store and retrieve the enum's value
field:
public class SomethingContainingAnAuthenticationMethod
{
[ProtoMember(1)]
public int AuthenticationMethodDataTransferField { get; set; }
public AuthenticationMethod AuthenticationMethod { get; set; }
[ProtoBeforeSerialization]
public void PopulateDataTransferField()
{
AuthenticationMethodDataTransferField = AuthenticationMethod.value;
}
[ProtoAfterDeserialization]
public void PopulateAuthenticationMethodField()
{
AuthenticationMethod = AuthenticationMethod.FromInt(AuthenticationMethodDataTransferField);
}
}
Any other ideas would be much appreciated.