This seems like a simple question on its surface but I thought I’d reach out to the community for this one. I am serializing .NET types in a stream and need some way to uniquely identify each type so that I know how to deserialize the type on the other side. I’ve thought of various approaches:
- Annotate each type with an attribute that requires an integer to identify the message type
- Do the same as #1 except use a GUID
- Hashing the fully qualified name
I would love to be able to do this without requiring the attribute. Using an integer is conflict prone. Generating GUIDs every time I create a new type is cumbersome. The third option seems possible but also has the possibility of conflicts, albeit somewhat isolated.
What I’d like to be able to do is infer this uniqueness in a deterministic way so that any object can be passed in and deserialized on the other end without having to mark it up somehow. Assume that I already have a way to register all known types on both ends, so before any message is sent, both ends already have a list of acceptable types. All I’d like to do is make the process of registering those known types less clunky.
Edit: I’d like to be as small on the wire as possible while still achieving the uniqueness I require.
You could use
Type.GUIDfor example…IF that does not fit your case please provide more details…