I would like to write a custom .NET serializer/deserializer for FIX messages (which aren’t like XML). Basically the message is coded as <tag>=<value>;<tag>=<value>;...
So a sample one might be:
51=2;20=hello;31=2
I would like to use my FIX Serializer class similar to the way I use the XMLSerializer class to be able to serialize/deserialize messages. I would imagine I would write a FIX message class like:
[Serializable]
public class FixMessage
{
[FIXValuePair(51)]
public double Price { get; set; }
[FIXValuePair(20)]
public string SomethingElse { get; set; }
}
Any pointers on how I would write such a Serializer/Deserializer?
Using reflection you can loop thru the properties of the object you are serializing, then for each property you can check for attributes (again using reflection). And in the end you send your output to a stream.
Your code could look something like this (simplified):