0

如何在函数中检查对象是否属于某种类型。这是我的代码:

Public Function IsSerializedObjectAValidObjectType(Of ObjectType)(FileName As String) As Boolean
    Dim ObjectToCheck As New Object
    ObjectToCheck = OpenObjectFromFile(FileName)
    Return ObjectToCheck.GetType Is ObjectType
End Function

以下代码从文件中获取对象。

ObjectToCheck = OpenObjectFromFile(FileName)
4

1 回答 1

0

尝试这个:

Public Function IsSerializedObjectAValidObjectType(Of T)(FileName As String) As Boolean
      Dim ObjectToCheck As New Object
      ObjectToCheck = OpenObjectFromFile(FileName)
      Return TypeOf ObjectToCheck.GetType Is T
End Function
于 2013-07-02T13:00:40.733 回答