Question

This is a great wiki article: http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx

However, it is missing code for the DataContractSerialize. I am pretty sure that this method is fairly simple, but, for completeness, it would be great to have an example.

Does one exists? Or, is there a working example of the code?

Thanks

S

Was it helpful?

Solution

Well, I think Jan Wilson left this out, since it's unessential for his AOP introduction and because there are several ways to serialize/dump data, you may read about it here:

http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/

So you could simply use the following:

private static void DataContractSerialize(object argument, Type argumentType)
{
    var settings = new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Auto };
    var serializer = new DataContractSerializer(argumentType);
    using (XmlWriter xml = XmlWriter.Create(YOUR_PATH_TO_LOGFILE_CONST_STRING, settings))
    {
        xml.WriteStartDocument();
        serializer.WriteObject(xml, argument);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top