Assert.IsInstanceOfType 方法 (Object, Type, String)

確認指定的物件是指定之型別的執行個體。 如果此型別不在物件的繼承階層架構內,判斷提示就會失敗。 如果判斷提示失敗,便顯示一則訊息。

命名空間:  Microsoft.VisualStudio.TestTools.UnitTesting
組件:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (在 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 中)

語法

'宣告
Public Shared Sub IsInstanceOfType ( _
    value As Object, _
    expectedType As Type, _
    message As String _
)
public static void IsInstanceOfType(
    Object value,
    Type expectedType,
    string message
)
public:
static void IsInstanceOfType(
    Object^ value, 
    Type^ expectedType, 
    String^ message
)
static member IsInstanceOfType : 
        value:Object * 
        expectedType:Type * 
        message:string -> unit 
public static function IsInstanceOfType(
    value : Object, 
    expectedType : Type, 
    message : String
)

參數

  • value
    型別:System.Object
    要驗證的物件屬於 expectedType。
  • expectedType
    型別:System.Type
    必須要位於 value 之繼承階層架構中的型別。
  • message
    型別:System.String
    要在判斷提示失敗時顯示的訊息。這項訊息會在單元測試結果中出現。

例外狀況

例外狀況 條件
AssertFailedException

value 為 nullNull 參照 (即 Visual Basic 中的 Nothing) 或 expectedType 不在 value 的繼承階層架構內。

.NET Framework 安全性

請參閱

參考

Assert 類別

IsInstanceOfType 多載

Microsoft.VisualStudio.TestTools.UnitTesting 命名空間

其他資源

使用 Assert 類別