我希望将一个HttpContext类型的对象写入xml文件。搜索我发现了几个使用XMLSerializer
的例子然而,由于HttpContext没有无参数构造函数,我无法使用XMLSerializer。
有解决方法吗?或者是否有另一种方法将对象写入xml文件?
当前代码:
public override async Task ProcessRequestAsync(HttpContext context)
{
DavEngineAsync engine = getOrInitializeEngine(context);
context.Response.BufferOutput = false;
DavContext ntfsDavContext = new DavContext(context);
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(HttpContext));
Guid myG = Guid.NewGuid();
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//" + myG.ToString() + " .xml";
System.IO.FileStream file = System.IO.File.Create(path);
writer.Serialize(file, context);
file.Close();
await engine.RunAsync(ntfsDavContext);
}