My XmlSerializer Pattern

The idea behind the .NET System.Xml.Serialization.XmlSerializer class is that you can easily serialize an XML file into a class tree and vice versa.

If you’re using XML Schema files, the xsd.exe tool can create that class tree for you.

But for simple applications you don’t even need a schema. You simply create a class that has public properties of simple types or complex types that in turn contain simple types.

Then you can throw this object into the XmlSerializer and you’re done. 🙂

Here’s my personal XmlSerializer coding pattern for a simple list of settings:

Read more

C# CodeDom Inline Compiling

I was a bit bored just now and since the WYSIWYG editor of WordPress 2.9.2 doesn’t work as optimal as I had hoped, I decided to write my own program that translates forum posts with BB code into HTML.

Of course I could have put all these replace functions into the code but then I would have to adapt the code every time I find a new tag.

So I thought this might be a good time to toy with the Inline Compiler of C#. And if done right, it is relatively easy.

Here’s my first Inline Compiling Code Snippet (it doesn’t contain any error handling and some such, but you get the idea how it works):

Read more