在.NET序列化的System.Drawing.Color [英] Serializing System.Drawing.Color in .NET

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

问题描述

我用默认的.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

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

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