C#中的序列化而不使用文件系统 [英] Serialization in C# without using file system
本文介绍了C#中的序列化而不使用文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的 2D 字符串数组,我想将它填充到 MOSS 中的 SPFieldMultiLineText 中.这映射到一个 ntext 数据库字段.
I have a simple 2D array of strings and I would like to stuff it into an SPFieldMultiLineText in MOSS. This maps to an ntext database field.
我知道我可以序列化为 XML 并存储到文件系统,但我想在不接触文件系统的情况下进行序列化.
I know I can serialize to XML and store to the file system, but I would like to serialize without touching the filesystem.
public override void ItemAdding(SPItemEventProperties properties)
{
// build the array
List<List<string>> matrix = new List<List<string>>();
/*
* populating the array is snipped, works fine
*/
// now stick this matrix into the field in my list item
properties.AfterProperties["myNoteField"] = matrix; // throws an error
}
看起来我应该能够做这样的事情:
Looks like I should be able to do something like this:
XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
properties.AfterProperties["myNoteField"] = s.Serialize.ToString();
但这不起作用.我找到的所有示例都演示了写入文本文件.
but that doesn't work. All the examples I've found demonstrate writing to a text file.
推荐答案
StringWriter outStream = new StringWriter();
XmlSerializer s = new XmlSerializer(typeof(List<List<string>>));
s.Serialize(outStream, myObj);
properties.AfterProperties["myNoteField"] = outStream.ToString();
这篇关于C#中的序列化而不使用文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文