小编jee*_*_jk的帖子

如何将对象标记为可序列化

我有一个system.document.table对象,我想将该对象标记为Serializable以便进行深度克隆。例外是程序集“ PresentationFramework,版本= 4.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35”中的类型“ System.Windows.Documents.Table”未标记为可序列化。

 FlowTable original =  new FlowTable();
 original = objFlowTab.deepclone();
Run Code Online (Sandbox Code Playgroud)

其中objflowtab具有表对象

[Serializable]
public class FlowTable : Table
{ ....
  ....
  public static class ExtensionMethods
{
    // Deep clone
    public static T DeepClone<T>(this T a)
    { 

        using (MemoryStream stream = new MemoryStream())
        {

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream,a);
            stream.Position = 0;
            return (T)formatter.Deserialize(stream);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在formatter.Serialize(stream,a)中遇到错误;

c# wpf documents serializable cloning

3
推荐指数
1
解决办法
3690
查看次数

标签 统计

c# ×1

cloning ×1

documents ×1

serializable ×1

wpf ×1