如何将Serializable / DeSerializable应用于Model3DGroup [英] How to apply Serializable/DeSerializable with Model3DGroup

查看:54
本文介绍了如何将Serializable / DeSerializable应用于Model3DGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

我有一个课程,其中包含以下内容:



Scenario:
I have a class which contains the following:

[Serializable]
public class Model
{
     public string Name { get; set; }
     public List<Camera> Cameras { get; set; }
     public int DefaultCamera { get; set; }

     public bool IsDefaultLightON { get; set; }
     public List<Light> Lights { get; set; }
     
     public Model3DGroup Models { get; set; }
     public ModelType ModelType { get; set; }
     
     public Model() { }
}





问题:

我已应用Serializable但我得到一个错误,Model3DGroup未标记为可序列化。



[错误:在程序集'PresentationCore中输入'System.Windows.Media.Media3D.Model3DGroup',版本= 4.0.0.0,文化=中立,PublicKeyToken = 31bf3856ad364e35 '未被标记为可序列化。]



想要实现:

将类转换为流



问题:

有没有通过序列化来解决这个问题的方法?

有没有其他解决方案可以将我的模型类转换为流?



Problem:
I have applied Serializable but i get an error that Model3DGroup is not marked as serializable.

[Error: "Type 'System.Windows.Media.Media3D.Model3DGroup' in Assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."]

Want to achieve:
Convert class to stream

Question:
Is there any solution to do this through serialization?
Is there any alternative solution to convert my "Model" class to stream?

推荐答案

你必须自己处理Model3DGroup的(反)序列化。



创建一个[ Serializable] -decorated类,派生自 Model3DGroup 并实现 ISerializable interface [ ^ ]。如果一切顺利,你应该可以用 SerializableModel3DGroup 替换原来的 Model3DGroup ,无论它发生什么变化都没有改变任何周围的代码。加上模型将是可序列化的。



困难或者tedius部分将是接口实现,这基本上意味着 GetObjectData(SerializationInfo,StreamingContext)方法和具有相同参数的构造函数。前者将您的对象转换为字节流,后者将恢复该过程。更准确地说,你必须让它表现得那样。但如何你实现这一点完全取决于 Model3DGroup 类以及你想要序列化它的内容(基本上所需的所有信息)重建其实例)。
You will have to handle the (de)serialization of Model3DGroup yourself.

Create a [Serializable]-decorated class that derives from Model3DGroup and implements the ISerializable interface[^]. If all goes well, you should be able to replace the original Model3DGroup by your SerializableModel3DGroup wherever it occurs without changing any of the surrounding code. Plus Model would be serializable.

The difficult or tedius part will then be the interface implementation, which basically means the GetObjectData(SerializationInfo, StreamingContext) method and a constructor with the same parameters. The former turns your object into a byte stream, the latter reverts the process. More precisely, you will have to make it behave like that. But how you're achieving this totally depends on the Model3DGroup class and what you want to serialize out of it (basically all information that is needed to reconstruct an instance thereof).


这篇关于如何将Serializable / DeSerializable应用于Model3DGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆