I've been reviewing some code that I maintain recently, and I came across this wrapper object for the serial port class. I'm trying to understand the advantage of this seemingly redundant object:
Public Class SerialPort_Class Private WithEvents Serial_Port As IO.Ports.SerialPort Private SerialPort_ReOpen_Flag As Boolean = True Private ReadOnly Common_Methods As New Common_Class Private _BaudRate As Integer = 115200 Private _DataBits As Integer = 8 Private _DiscardNull As Boolean = False Private _DtrEnable As Boolean = False Private _Encoding As Text.Encoding = Text.Encoding.ASCII Private _Handshake As IO.Ports.Handshake = IO.Ports.Handshake.None Private _NewLine As String = vbLf 'Default Private _Parity As IO.Ports.Parity = IO.Ports.Parity.None Private _ParityReplace As Byte = Byte.MinValue 'If the value is set to the null character, parity replacement is disabled Private _PortName As String = "None" 'Default of Nothing, Prevent Occupying Com Port Until Set Private _ReadBufferSize As Integer = 4096 Private _ReadTimeout As Integer = 250 Private _ReceivedBytesThreshold As Integer = 1 Private _RtsEnable As Boolean = False Private _StopBits As IO.Ports.StopBits = IO.Ports.StopBits.One Private _WriteBufferSize As Integer = 2048 Private _WriteTimeout As Integer = 250 Private Shared ReadOnly Search_Com_Lock_Object As New Object Public Property BaudRate As Integer Get Return _BaudRate End Get Set(value As Integer) If value.Equals(_BaudRate) Then Return _BaudRate = value SerialPort_ReOpen_Flag = True End Set End Property Public Property DataBits As Integer Get Return _DataBits End Get Set(value As Integer) If value.Equals(_DataBits) Then Return _DataBits = value SerialPort_ReOpen_Flag = True End Set End Property Public Property DiscardNull As Boolean Get Return _DiscardNull End Get Set(value As Boolean) If value.Equals(_DiscardNull) Then Return _DiscardNull = value SerialPort_ReOpen_Flag = True End Set End Property Public Property DtrEnable As Boolean Get Return _DtrEnable End Get Set(value As Boolean) If value.Equals(_DtrEnable) Then Return _DtrEnable = value SerialPort_ReOpen_Flag = True End Set End Property Public Property Encoding As Text.Encoding Get Return _Encoding End Get Set(value As Text.Encoding) If value.Equals(_Encoding) Then Return _Encoding = value SerialPort_ReOpen_Flag = True End Set End Property Public Property Handshake As IO.Ports.Handshake Get Return _Handshake End Get Set(value As IO.Ports.Handshake) If value.Equals(_Handshake) Then Return _Handshake = value SerialPort_ReOpen_Flag = True End Set End Property Public Property NewLine As String Get Return _NewLine End Get Set(value As String) If value.Equals(_NewLine) Then Return _NewLine = value SerialPort_ReOpen_Flag = True End Set End Property Public Property Parity As IO.Ports.Parity Get Return _Parity End Get Set(value As IO.Ports.Parity) If value.Equals(_Parity) Then Return _Parity = value SerialPort_ReOpen_Flag = True End Set End Property Public Property ParityReplace As Byte Get Return _ParityReplace End Get Set(value As Byte) If value.Equals(_ParityReplace) Then Return _ParityReplace = value SerialPort_ReOpen_Flag = True End Set End Property Public Property PortName As String Get Return _PortName End Get Set(value As String) If value.Equals(_PortName) Then Return _PortName = value SerialPort_ReOpen_Flag = True End Set End Property Public Property ReadBufferSize As Integer Get Return _ReadBufferSize End Get Set(value As Integer) If value.Equals(_ReadBufferSize) Then Return _ReadBufferSize = value SerialPort_ReOpen_Flag = True End Set End Property Public Property ReadTimeout As Integer Get Return _ReadTimeout End Get Set(value As Integer) If value.Equals(_ReadTimeout) Then Return _ReadTimeout = value SerialPort_ReOpen_Flag = True End Set End Property Public Property ReceivedBytesThreshold As Integer Get Return _ReceivedBytesThreshold End Get Set(value As Integer) If value.Equals(_ReceivedBytesThreshold) Then Return _ReceivedBytesThreshold = value SerialPort_ReOpen_Flag = True End Set End Property Public Property RtsEnable As Boolean Get Return _RtsEnable End Get Set(value As Boolean) If value.Equals(_RtsEnable) Then Return _RtsEnable = value SerialPort_ReOpen_Flag = True End Set End Property Public Property StopBits As IO.Ports.StopBits Get Return _StopBits End Get Set(value As IO.Ports.StopBits) If value.Equals(_StopBits) Then Return _StopBits = value SerialPort_ReOpen_Flag = True End Set End Property Public Property WriteBufferSize As Integer Get Return _WriteBufferSize End Get Set(value As Integer) If value.Equals(_WriteBufferSize) Then Return _WriteBufferSize = value SerialPort_ReOpen_Flag = True End Set End Property Public Property WriteTimeout As Integer Get Return _WriteTimeout End Get Set(value As Integer) If value.Equals(_WriteTimeout) Then Return _WriteTimeout = value SerialPort_ReOpen_Flag = True End Set End Property