是否有任何源代码,随着温莎城堡日志拦截器的例子



这是一篇很棒的wiki文章:http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx

但是,它缺少DataContractSerialize的代码。我确信这个方法相当简单,但是为了完整起见,最好有一个示例。

存在吗?或者,是否有代码的工作示例?

感谢

S

嗯,我认为Jan Wilson遗漏了这一点,因为这对他的AOP介绍来说不是必要的,而且因为有几种方法可以序列化/转储数据,您可以在这里阅读:

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

所以你可以简单地使用以下命令:

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);
    }
}

最新更新