在运行时将对象标记为可序列化 [英] Mark an Object as Serializable in Run Time

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

问题描述

您好,

我正在使用序列化问题的第三方组件,因为开发人员可能忘记在控件前加上[Serializable()]或像这样......

I'm using a third part component that has a problem with serialization because the developers probably forgotten to prefix the control with the [Serializable()] or something like this..

因此,当需要序列化时,控件会导致异常。

So, the control causes an exception when needs to be serializable.

 

是否可以将该控件标记为可序列化?或者,更深入,是否可以修补程序集(或.exe)来纠正问题?我怎么能这样做?

Would it be possible to mark that control as serializable? Or, going deeper, would it be possible to patch the assembly (or .exe) to correct the issue? How could I do that?

 

提前致谢。

推荐答案

我认为这是可能的。

I dot think it is possible.

你可以做的是使用system.reflection做一些研究。您可以将对象复制到您的某个对象中并序列化您的对象,并在您更改时更新其对象。

What you could do is use system.reflection do some research on it. You could copy object into one of your object and serialize yours and when yours change update their object.

string key = object.GetType().FullName;

PropertyInfo[] properties = System.Runtime.Remoting.Messaging.CallContext.GetData(key) as PropertyInfo[];
      if (properties == null)
      {
        ArrayList items = new ArrayList();
        PropertyInfo[] pageProperties = this.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
        foreach (PropertyInfo property in pageProperties)
        {
          if (property.CanRead)
          {
            string name = property.Name;
            object v = property.GetValue(this, null);

...


这篇关于在运行时将对象标记为可序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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