如何将序列化类保存到文件并再次检索它

时间:2017-11-18 06:29:49

标签: c# vb.net serialization

我使用此代码记录鼠标和键盘事件并对其进行回复:

Namespace GlobalMacroRecorder
    <Serializable()>
    Public Enum MacroEventType
        MouseMove
        MouseDown
        MouseUp
        MouseWheel
        KeyDown
        KeyUp
    End Enum

    <Serializable()>
    Public Class MacroEvent
        Public MacroEventType As MacroEventType
        Public EventArgs As EventArgs
        Public TimeSinceLastEvent As Integer

        Public Sub New(ByVal macroEventType As MacroEventType, ByVal eventArgs As EventArgs, ByVal timeSinceLastEvent As Integer)
            MyBase.New
            Me.MacroEventType = macroEventType
            Me.EventArgs = eventArgs
            Me.TimeSinceLastEvent = timeSinceLastEvent
        End Sub
    End Class
End Namespace

我将事件存储在events1:

Private events1 As List(Of MacroEvent) = New List(Of MacroEvent)

如何将event1保存到文件并再次检索?

0 个答案:

没有答案