在DataContractSerializer.WriteObject之后缺少XmlBinaryWriterSession中的字符串

时间:2011-11-22 16:13:36

标签: c# .net serialization datacontractserializer

说我有:

[DataContract(Name=,Namespace=)]    
[KnownType(typeof(B))]
class A
{
    [DataMember]
    public B B{get;set;}
}

[DataContract(Name=,Namespace=)]
class B
{
    public string Something{get;set;}
}

...

// ms = memory stream
// writerSession  = XmlBinaryWriterSession
using (var writer = XmlDictionaryWriter.CreateBinaryWriter(ms, null, writerSession))
    {
                var serializer = new DataContractSerializer(typeof(SerializedFeedItem));
                serializer.WriteObject(writer, serItem);
                writer.Flush();
                ...
    }

现在我看到只有A类的xml字典字符串被添加到编写器会话中。我想知道如何让串行器也写出类型B的字符串。 问题与使用XmlDictionary相关技术压缩序列化内容有关。

提前致谢。

0 个答案:

没有答案