zoukankan      html  css  js  c++  java
  • 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域,不知道哪位高人指点下该怎么处理这样的情况。

  • 相关阅读:
    Shell 脚本基本操作练习
    Unix 环境高级编程---线程创建、同步、
    ubuntu 安装ssh-server时出现错误:openssh-server: Depends: openssh-client (= 1:5.3p1-3ubuntu3) but 1:5.3p1-3ubuntu4 is to be installed
    python set 集合
    python 深浅拷贝
    用户权限管理
    vim 编辑器的使用
    linux系统初体验
    平滑升级nginx
    在windows下如何使用密钥对远程登录服务器?
  • 原文地址:https://www.cnblogs.com/Render/p/254010.html
Copyright © 2011-2022 走看看