Skip to content

Latest commit

 

History

History
29 lines (16 loc) · 1.73 KB

iii.4.6-isinst.md

File metadata and controls

29 lines (16 loc) · 1.73 KB

III.4.6 isinst – test if an object is an instance of a class or interface

Format Assembly Format Description
75 <T> isinst typeTok Test if obj is an instance of typeTok, returning null or an instance of that class or interface.

Stack Transition:

…, obj → …, result

Description:

typeTok is a metadata token (a typeref, typedef or typespec), indicating the desired class. If typeTok is a non-nullable value type or a generic parameter type it is interpreted as "boxed" typeTok. If typeTok is a nullable type, Nullable<T>, it is interpreted as "boxed" T.

The isinst instruction tests whether obj (type O) is an instance of the type typeTok. If the actual type (not the verifier tracked type) of obj is verifier-assignable-to the type typeTok then isinst succeeds and obj (as result) is returned unchanged while verification tracks its type as typeTok. Unlike coercions (§III.1.6) and conversions (§III.3.27), isinst never changes the actual type of an object and preserves object identity (see Partition I).

If obj is null, or obj is not verifier-assignable-to the type typeTok, isinst fails and returns null.

Exceptions:

System.TypeLoadException is thrown if typeTok cannot be found. This is typically detected when CIL is converted to native code rather than at runtime.

Correctness:

Correct CIL ensures that typeTok is a valid typeref or typedef or typespec token, and that obj is always either null or an object reference.

Verifiability:

Verification tracks the type of result as typeTok.