我的想法是通过封装 StreamReader 和 StreamWriter 类让我的生活更轻松,这里的目标是让这个类提供静态方法,我可以调用这些方法来从文件中写入和读取,而不必实例化 StreamWriter/Reader 类型的对象等等。
到目前为止,我的班级有以下代码:
Option Strict On
Imports System.IO
Imports System.IO.StreamReader
Imports System.IO.StreamWriter
Public Class ReadWrite
Enum WriteType
Append = 0
WriteLine = 1
Write = 2
End Enum
Enum ReadType
Readline = 0
Read = 1
End Enum
Shared Function Write (ByVal FilePath As String, ByVal _WriteType As WriteType, ByVal Content As String) As Boolean
Select Case _WriteType
Case WriteType.Append
Using _append As StreamWriter = New StreamWriter(FilePath,True)
_append.WriteLine (Content)
End Using
Case WriteType.Write
Using _write As StreamWriter = New StreamWriter(FilePath, False)
_write.Write (Content)
End Using
Case WriteType.WriteLine
Using _writeline As StreamWriter = New StreamWriter(FilePath, False)
_writeline.Writeline (Content)
End Using
End Select
Return false
End Function
Shared Function Read (ByVal FilePath As String, ByVal _ReadType As ReadType) As Boolean
Select Case _ReadType
Case ReadType.ReadLine
Case ReadType.Read
End Select
Return false
End Function
End Class
问题: 这是完成此类任务的好方法吗?我可以使用哪些技术来产生良好的结果,同时保持代码的可重用性和简单性;我的目标是让它足够灵活,以便在其他应用程序中轻松使用。
谢谢!