📄 operators.vb
字号:
Return CType(s, SByte) End Function Private Shared Function AddSingles(ByVal o1 As Single, ByVal o2 As Single) As Object Return o1 + o2 End Function Private Shared Function AddStrings(ByVal o1 As String, ByVal o2 As String) As Object Return o1 + o2 End Function Private Shared Function AddUInt16s(ByVal o1 As UShort, ByVal o2 As UShort) As Object Dim int As Integer = CType(o1, Integer) + o2 If (int > UShort.MaxValue) Then Return int End If Return CType(int, UShort) End Function Private Shared Function AddUInt32s(ByVal o1 As UInteger, ByVal o2 As UInteger) As Object Dim l As Long = CType(o1, Long) + o2 If (l > UInteger.MaxValue) Then Return l End If Return CType(l, UInteger) End Function Private Shared Function AddUInt64s(ByVal o1 As ULong, ByVal o2 As ULong) As Object Return o1 + o2 End Function Public Shared Function AddObject(ByVal o1 As Object, ByVal o2 As Object) As Object If (o1 Is Nothing) And (o2 Is Nothing) Then Return 0 End If If (o1 Is Nothing) Then o1 = CreateNullObjectType(o2) End If If (o2 Is Nothing) Then o2 = CreateNullObjectType(o1) End If Dim destTc As TypeCode = DestTypeCodeOpAdd(o1, o2) Try Select Case destTc 'Case TypeCode.Empty -> break Case TypeCode.Boolean Return AddBooleans(VBConvert.ToBoolean(o1), VBConvert.ToBoolean(o2)) Case TypeCode.Byte Return AddBytes(VBConvert.ToByte(o1), VBConvert.ToByte(o2)) Case TypeCode.Char Return AddChars(VBConvert.ToChar(o1), VBConvert.ToChar(o2)) Case TypeCode.DateTime Return AddDateTimes(VBConvert.ToDateTime(o1), VBConvert.ToDateTime(o2)) Case TypeCode.Decimal Return AddDecimals(VBConvert.ToDecimal(o1), VBConvert.ToDecimal(o2)) Case TypeCode.Double Return AddDoubles(VBConvert.ToDouble(o1), VBConvert.ToDouble(o2)) Case TypeCode.Int16 Return AddInt16s(VBConvert.ToInt16(o1), VBConvert.ToInt16(o2)) Case TypeCode.Int32 Return AddInt32s(VBConvert.ToInt32(o1), VBConvert.ToInt32(o2)) Case TypeCode.Int64 Return AddInt64s(VBConvert.ToInt64(o1), VBConvert.ToInt64(o2)) Case TypeCode.SByte Return AddSBytes(VBConvert.ToSByte(o1), VBConvert.ToSByte(o2)) Case TypeCode.Single Return AddSingles(VBConvert.ToSingle(o1), VBConvert.ToSingle(o2)) Case TypeCode.String Return AddStrings(VBConvert.ToString(o1), VBConvert.ToString(o2)) Case TypeCode.UInt16 Return AddUInt16s(VBConvert.ToUInt16(o1), VBConvert.ToUInt16(o2)) Case TypeCode.UInt32 Return AddUInt32s(VBConvert.ToUInt32(o1), VBConvert.ToUInt32(o2)) Case TypeCode.UInt64 Return AddUInt64s(VBConvert.ToUInt64(o1), VBConvert.ToUInt64(o2)) End Select Return AddObjects(o1, o2) Catch ex As Exception End Try Throw New InvalidCastException("Operator '+' is not defined for type '" + GetTypeCode(o1).ToString() + "' and type '" + GetTypeCode(o2).ToString() + "'.") End Function 'creates a real type of a Nothing object Private Shared Function CreateNullObjectType(ByVal otype As Object) As Object If TypeOf otype Is Byte Then Return VBConvert.ToByte(0) ElseIf TypeOf otype Is Boolean Then Return VBConvert.ToBoolean(False) ElseIf TypeOf otype Is Long Then Return VBConvert.ToInt64(0) ElseIf TypeOf otype Is Decimal Then Return VBConvert.ToDecimal(0) ElseIf TypeOf otype Is Short Then Return VBConvert.ToInt16(0) ElseIf TypeOf otype Is Integer Then Return VBConvert.ToInt32(0) ElseIf TypeOf otype Is Double Then Return VBConvert.ToDouble(0) ElseIf TypeOf otype Is Single Then Return VBConvert.ToSingle(0) ElseIf TypeOf otype Is String Then Return VBConvert.ToString("") ElseIf TypeOf otype Is Char Then Return VBConvert.ToChar(0) ElseIf TypeOf otype Is Date Then Return Nothing Else Throw New NotImplementedExceptio
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -