Serializing System.Drawing.Color in .NET

后端 未结 2 1323
名媛妹妹
名媛妹妹 2021-01-21 03:08

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

2条回答
  •  旧巷少年郎
    2021-01-21 03:24

    Using ISerializable is not the recommended way to deal with versioning. The [OptionalField] is, the ins and outs are well described in this MSDN library article.

    Answering your question: SerializationInfo.GetValue("fieldName", typeof(Color)) ought to give you the color. You'll need to cast the return value.

提交回复
热议问题