Having fun with Reflection and custom Attributes
I’ve got a very weird project:
I have to convert a message into a string-array and a protocol code and back. The communication layer can only send fields of string. I know, I could serialize, zip and encode as base64 for example. But that’s not an option. Why? That’s top secret.
It has to be one string-value per field.
Another constraint is, that there are a lot of different messages. So it would be quite stupid to handcode the “translationroutine” every time. The messages have to be “real” objects and having Intellisense support is a must. Plus performance is not a big issue. That just sounds like using a Registry/AbstractFactory Pattern with heavy reflection.
Well, satisfying these constraint is actually quite simple. All we need is an Attribute marking classes as message representations and another one marking the Properties that should be used to compile the string array. After defining these two attributes it is quite easy to find all the message definitions in an assembly…
Uh, gotta run. More to follow. ![]()

[...] For all of you waiting for the continuation of my previous partial post about custom attributes and reflection. Well, hopefully it will be done on Monday. I’ll be spending a LOT of time in trains the next 4 days. And that should create enough “spare” time for me to finish my work on a hopefully informative article about custom attributes, reflection and setting values dynamically at runtime. So stay tuned and be sure to check back on Tuesday. May 25th, 2006 12:35 am – Random Thoughts, Personal [...]
Pingback on May 25, 2006 @ 00:35:16