• delegate或event序列化的一个问题


    有这样一个类:
    <Serializable()> Public Class CustLabelProperty
        Private m_iTop, m_iLeft As Integer
        Private m_bSuspendPropertyChanged As Boolean
        Public Delegate Sub PropertyChangedHandler()
        Public Event PropertyChanged As PropertyChangedHandler
        Public Sub SuspendPropertyChanged()
            m_bSuspendPropertyChanged = True
        End Sub
        Public Sub ResumePropertyChanged()
            m_bSuspendPropertyChanged = False
        End Sub
        Protected Sub OnPropertyChanged()
            If Not m_bSuspendPropertyChanged Then
                RaiseEvent PropertyChanged()
            End If
        End Sub
        <Browsable(True), Description("左上角的Y坐标"), Category("显示")> Public Property Top() As Integer
            Get
                Return m_iTop
            End Get
            Set(ByVal Value As Integer)
                m_iTop = Value
                OnPropertyChanged()
            End Set
        End Property
        <Browsable(True), Description("左上角的X坐标"), Category("显示")> Public Property Left() As Integer
            Get
                Return m_iLeft
            End Get
            Set(ByVal Value As Integer)
                m_iLeft = Value
                OnPropertyChanged()
            End Set
        End Property
    End Class

    假如我生成这样一个类:
    Dim aCustLabelProperty As New CustLabelProperty
    aCustLabelProperty.Left = 10
    这时序列化是可以的,序列化代码如下:
           Dim BFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            Dim StreamFile As FileStream
            StreamFile = New FileStream("d:\aaa.xxx", FileMode.Create)
            With BFormatter
                .FilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Low
                .AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                .Serialize(StreamFile, aCustLabelProperty)
            End With
            StreamFile.Close()

    但是生成CustLabelProperty后如果我加上一句:
    AddHandler m_CustLabelProperty.PropertyChanged, AddressOf UpdateLabelProperty
    即给PropertyChanged赋值了。 由于UpdateLabelProperty所在类是不可以序列化的,这时序列化就会出错,错误为
    UpdateLabelProperty 所在的类未标记为可序列化。

    但是<noserialize()>标记又不可以用于event域,不知道哪位高人指点下该怎么处理这样的情况。

  • 相关阅读:
    openvas漏洞扫描
    MSF基础应用
    MS11-050安全漏洞
    MS08_067漏洞渗透攻击实践
    Adobe阅读器渗透攻击
    详解CentOS7安装配置vsftp搭建FTP
    zabbix英文切换成中文
    代理抛出异常 : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: 你的主机名: 你的主机名
    安装zabbix客户端
    Docker报错:“WARNING: IPv4 forwarding is disabled. Networking will not work.”解决。
  • 原文地址:https://www.cnblogs.com/Render/p/254010.html
Copyright © 2020-2023  润新知