在.NET序列化的System.Drawing.Color序列化、NET、System、Color

2023-09-03 05:54:10 作者:?青春修炼手册/*

我用默认的.NET序列化一类具有一个System.Drawing.Color成员。在code是现在人们所使用,而我需要一个额外的成员添加到类,但还是反序列化的旧版本。

I've used the default .NET serialization for a class with a System.Drawing.Color member. The code is now in use by people, and I need to add an extra member to the class, but still deserialize older versions.

所以,我想这样做的标准方式:ISerializable接口,使用的SerializationInfo方法来获取int和string成员

So I tried the standard way of doing this: The ISerializable interface, using SerializationInfo methods to get the int and string members.

的问题:我的类也有一​​个System.Drawing.Color构件,但SerializationInfo中不提供GETCOLOR方法读取该数据类型。我试着得到它作为一个int和一个字符串,并将其铸造的System.Drawing.Color,但没有运气。

The problem: My class also has a System.Drawing.Color member, but SerializationInfo doesn't provide a "GetColor" method read this data type. I've tried getting it as an int and as a string, and casting it to System.Drawing.Color, but no luck.

有谁知道如何从SerializationInfo中反序列化一个System.Drawing.Color?

Does anyone know how to deserialize a System.Drawing.Color from SerializationInfo?

推荐答案

我已经用这样的事情在过去。

I have used something like this in the past.

 <Xml.Serialization.XmlIgnore()> Public BackColour As Drawing.Color

        Public Property xmlBackColour() As Integer
            Get
                Return BackColour.ToArgb
            End Get
            Set(ByVal value As Integer)
                BackColour = Drawing.Color.FromArgb(value)
            End Set
        End Property