Type.IsInstanceOfType メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim o As Object Dim returnValue As Boolean returnValue = instance.IsInstanceOfType(o)
戻り値
true が返されるのは、現在の Type が o によって表されるオブジェクトの継承可能な階層内にある場合、または現在の Type が o にサポートされるインターフェイスである場合です。false が返されるのは、これらの条件のいずれも満たされない場合、または o が null 参照 (Visual Basic では Nothing) であるか、現在の Type がオープン ジェネリック型である (つまり、ContainsGenericParameters が true を返す) 場合です。

![]() |
---|
構築型は、このジェネリック型定義のインスタンスではありません。つまり、MyGenericList<int> (Visual Basic の場合は MyGenericList(Of Integer)) は MyGenericList<T> (Visual Basic の場合は MyGenericList(Of T)) のインスタンスではありません。 |

IsInstanceOfType メソッドの使用例を次に示します。
Imports System Public Interface IMyIfc End Interface 'IMyIfc Public Class [MyClass] Implements IMyIfc End Class '[MyClass] Public Class MyDerivedClass Inherits [MyClass] End Class 'MyDerivedClass Class IsInstanceTest Public Shared Sub Main() Dim imyifcType As Type = GetType(IMyIfc) Dim mc As New [MyClass]() Dim mcType As Type = mc.GetType() Dim mdc = New MyDerivedClass() Dim mdcType As Type = mdc.GetType() Dim array(10) As Integer Dim arrayType As Type = GetType(Array) Console.WriteLine("Is int[] an instance of the Array class? {0}.", arrayType.IsInstanceOfType(array)) Console.WriteLine("Is myclass an instance of MyClass? {0}.", mcType.IsInstanceOfType(mc)) Console.WriteLine("Is myderivedclass an instance of MyClass? {0}.", mcType.IsInstanceOfType(mdc)) Console.WriteLine("Is myclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mc)) Console.WriteLine("Is myderivedclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mdc)) End Sub 'Main End Class 'IsInstanceTest
using System; public interface IMyIfc {} public class MyClass : IMyIfc {} public class MyDerivedClass : MyClass {} class IsInstanceTest { public static void Main() { Type imyifcType=typeof(IMyIfc); MyClass mc = new MyClass(); Type mcType = mc.GetType(); MyClass mdc = new MyDerivedClass(); Type mdcType = mdc.GetType(); int [] array = new int [10]; Type arrayType = typeof(Array); Console.WriteLine("Is int[] an instance of the Array class? {0}.", arrayType.IsInstanceOfType(array)); Console.WriteLine("Is myclass an instance of MyClass? {0}.", mcType.IsInstanceOfType(mc)); Console.WriteLine("Is myderivedclass an instance of MyClass? {0}." , mcType.IsInstanceOfType(mdc)); Console.WriteLine("Is myclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mc)); Console.WriteLine("Is myderivedclass an instance of IMyIfc? {0}.", imyifcType.IsInstanceOfType(mdc)); } }
using namespace System; interface class IMyIfc{}; public ref class MyClass: public IMyIfc{}; public ref class MyDerivedClass: public MyClass{}; int main() { Type^ imyifcType = IMyIfc::typeid; MyClass^ mc = gcnew MyClass; Type^ mcType = mc->GetType(); MyClass^ mdc = gcnew MyDerivedClass; Type^ mdcType = mdc->GetType(); array<Int32>^arr = gcnew array<Int32>(10); Type^ arrayType = Array::typeid; Console::WriteLine( "Is Int32[] an instance of the Array class? {0}.", arrayType->IsInstanceOfType( arr ) ); Console::WriteLine( "Is myclass an instance of MyClass? {0}.", mcType->IsInstanceOfType( mc ) ); Console::WriteLine( "Is myderivedclass an instance of MyClass? {0}.", mcType->IsInstanceOfType( mdc ) ); Console::WriteLine( "Is myclass an instance of IMyIfc? {0}.", imyifcType->IsInstanceOfType( mc ) ); Console::WriteLine( "Is myderivedclass an instance of IMyIfc? {0}.", imyifcType->IsInstanceOfType( mdc ) ); }
import System.*; public interface IMyIfc { } //IMyIfc public class MyClass implements IMyIfc { } //MyClass public class MyDerivedClass extends MyClass { } //MyDerivedClass class IsInstanceTest { public static void main(String[] args) { Type imyifcType = IMyIfc.class.ToType(); MyClass mc = new MyClass(); Type mcType = mc.GetType(); MyClass mdc = new MyDerivedClass(); Type mdcType = mdc.GetType(); int array[] = new int[10]; Type arrayType = Array.class.ToType(); Console.WriteLine("Is int[] an instance of the Array class? {0}.", System.Convert.ToString(arrayType.IsInstanceOfType(array))); Console.WriteLine("Is myclass an instance of MyClass? {0}.", System.Convert.ToString(mcType.IsInstanceOfType(mc))); Console.WriteLine("Is myderivedclass an instance of MyClass? {0}." , System.Convert.ToString(mcType.IsInstanceOfType(mdc))); Console.WriteLine("Is myclass an instance of IMyIfc? {0}.", System.Convert.ToString(imyifcType.IsInstanceOfType(mc))); Console.WriteLine("Is myderivedclass an instance of IMyIfc? {0}.", System.Convert.ToString(imyifcType.IsInstanceOfType(mdc))); } //main } //IsInstanceTest

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_Type.IsInstanceOfType メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As _Type Dim o As Object Dim returnValue As Boolean returnValue = instance.IsInstanceOfType(o)
戻り値
true が返されるのは、現在の Type が o によって表されるオブジェクトの継承可能な階層内にある場合、または現在の Type が o にサポートされるインターフェイスである場合です。false が返されるのは、これらの条件のいずれも満たされない場合、または o が null 参照 (Visual Basic では Nothing) であるか、現在の Type がオープン ジェネリック型である (つまり、ContainsGenericParameters が true を返す) 場合です。

このメソッドは、アンマネージ コードからマネージ クラスにアクセスするためのメソッドであるため、マネージ コードからは呼び出さないでください。
Type.IsInstanceOfType メソッドは、指定したオブジェクトが現在の Type のインスタンスであるかどうかを判断します。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Type.IsInstanceOfTypeのページへのリンク