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. |
…, obj → …, result
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.
System.TypeLoadException
is thrown if typeTok cannot be found. This is typically detected when CIL is converted to native code rather than at runtime.
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.
Verification tracks the type of result as typeTok.