序列化问题 [英] Serialization questions

查看:83
本文介绍了序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已接近完成版本1.0的基本功能。


我有一个广泛的对象模型,我现在想要使用
$ b $持久保存我的对象b序列化。

我选择了binaryformatter进行序列化和自定义序列化,我知道这将使我能够灵活地在不打破旧事物时使用

将来会向会员添加会员并发送给现有客户。


1.)还有其他需要考虑的自定义序列化


2.)当在GetObjectData中执行info.addvalue时,如果我的类的一个成员是另一个类的实例,那么我是否继续添加它 - 那个

以某种方式调用该类的序列化过程来填充这个?


3.)我的一些类是集合。它们继承自collectionbase。

集合库是不可序列化的?假设它可能不是可序列化的,

文档说序列化将失败。如果是这样,世界上如何处理这个问题?我需要序列化收集库的所有项目

然后反序列化它们。


还有其他任何评论吗?还有其他的问题吗?


非常感谢。


Shane

My app is near completed for the basic feature of version 1.0.

I have an extensive object model and I now want to persist my objects using
serialization.
I have chosen binaryformatter to serialize, and custom serialization, which
I understand will allow me the flexibility of not breaking old things when I
add members to classes in the future and send to existing customers.

1.) is there anything else to consider with the custom serialization

2.) when doing the info.addvalue in GetObjectData, if one of the members of
my class is an instance of another class, do I go ahead and add it--and that
somehow calls the serialization process of that class to fullfill this?

3.) some of my classes are collections. They inherited from collectionbase.
Is collection base not serializable? Assuming it may not be serializable,
the documentation says serialization will fail. If so, how in the world can
I handle this issue? I need to serialize all items of the collection base
and then deserialize them.

Are there any other comments about this? Any other gotchas?

Thanks a bunch.

Shane

推荐答案

SSStory,


我见过最好的,我不能让它变得更好。


\\\ Tom Shelton

私函数SerializeFontObject(ByVal fnt As Font)As String

Dim bf As New BinaryFormatter

Dim mem As New MemoryStream

尝试

bf.Serialize(mem,fnt)

返回Convert.ToBase64String(mem.ToArray())

Catch

返回String.Empty

最后

mem.Close()

结束尝试

结束函数

私函数DeserializeFontObject(ByVal fnt As String)As Font

Dim bf As New BinaryFormatter

Dim mem As New MemoryStream(Convert。 FromBase64String(fnt))

试试

返回DirectCast(bf.Deserialize(mem),字体)

最后

如果没有mem则没有那么

mem.Close()

结束如果

结束尝试

结束功能

////


我希望这有点帮助吗?


Cor
SSStory,

The nicest I have seen, I cannot make it nicer.

\\\Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
////

I hope this helps a little bit?

Cor


感谢您的尝试。

我不喜欢看看这是如何回答我的任何一个问题。

我已经知道如何做二进制格式化程序,我在

的地方有代码。只是遇到原始问题中提到的麻烦,知道

如何序列化一个继承自collectionbase的类

显然是不可序列化的。


还有另外一个问题。


三分之一可能是如何判断一个类是否可序列化如果我不是

有源 - 比如CollectionBase?


谢谢Cor,


Shane

" ; Cor Ligthert <无************ @ planet.nl>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP14.phx.gbl ...
Thanks for trying.
I don''t see how this answers either of my questions.
I do already know how to do the binary formatter and I have that code in
place. Just having trouble as mentioned in the original question, knowing
for one how do I serialize a class that inherits from collectionbase which
apparently isn''t serializable.

And the other question also.

A third could be how do I find out if a class is serializable if I don''t
have the source--like CollectionBase?

Thanks Cor,

Shane
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
SSStory,

我见过最好的,我不能让它更好。

\\\ Tom Shelton
私函数SerializeFontObject(ByVal fnt As Font)As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
尝试
bf.Serialize(mem,fnt)
返回Convert.ToBase64String(mem.ToArray() )
Catch
返回String.Empty
最后
mem.Close()
结束尝试
结束功能

私人功能DeserializeFontObject(ByVal fnt As String)As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
尝试
返回DirectCast(bf.Deserialize (mem),字体)
最后
如果不是mem什么都没有en
mem.Close()
结束如果
结束尝试
结束功能
////

我希望这有点帮助位?

SSStory,

The nicest I have seen, I cannot make it nicer.

\\\Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
////

I hope this helps a little bit?

Cor





文档中列出了属性。 CollectionBase文档说:


< Serializable>

MustInherit Public Class CollectionBase

实现IList,ICollection,IEnumerable


所以,是的,CollectionBase是可序列化的。


祝你好运,


Sam

星期六,2005年4月2日15:43:58 -0600,SStory

< Th ******* @ TAKEOUTTHISSPAMBUSTERsofthome.net>写道:

Attributes are listed in the docs. CollectionBase docs say:

<Serializable>
MustInherit Public Class CollectionBase
Implements IList, ICollection, IEnumerable

So, yes, CollectionBase is serializable.

Best regards,

Sam
On Sat, 2 Apr 2005 15:43:58 -0600, "SStory"
<Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote:
感谢您的尝试。
我不知道这是如何回答我的任何问题。
我已经知道如何做二进制格式化程序我在
的地方有这个代码。只是遇到原始问题中提到的麻烦,知道如何序列化一个继承自集合库的类,它显然是不可序列化的。

另一个还有一个问题。

如果我没有源代码 - 比如CollectionBase,我怎么知道一个类是否可序列化?
谢谢Cor,

Shane
Thanks for trying.
I don''t see how this answers either of my questions.
I do already know how to do the binary formatter and I have that code in
place. Just having trouble as mentioned in the original question, knowing
for one how do I serialize a class that inherits from collectionbase which
apparently isn''t serializable.

And the other question also.

A third could be how do I find out if a class is serializable if I don''t
have the source--like CollectionBase?

Thanks Cor,

Shane




B-Line现在正在招聘一个华盛顿特区VB.NET

WinForms + WebServices职位的开发人员。

中级到高级开发人员。获取

信息或将电子邮件简历应用于

sam_blinex_com。



B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.


这篇关于序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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