Type.IsInstanceOfType(Object) Type.IsInstanceOfType(Object) Type.IsInstanceOfType(Object) Type.IsInstanceOfType(Object) Method

정의

지정된 개체가 현재 Type의 인스턴스인지를 확인합니다.Determines whether the specified object is an instance of the current Type.

public:
 virtual bool IsInstanceOfType(System::Object ^ o);
public virtual bool IsInstanceOfType (object o);
abstract member IsInstanceOfType : obj -> bool
override this.IsInstanceOfType : obj -> bool
Public Overridable Function IsInstanceOfType (o As Object) As Boolean

매개 변수

o
Object Object Object Object

현재 형식과 비교할 개체입니다.The object to compare with the current type.

반환

현재 Typeo가 나타내는 개체의 상속 계층 구조에 속하거나 현재 Typeo가 구현하는 인터페이스이면 true입니다.true if the current Type is in the inheritance hierarchy of the object represented by o, or if the current Type is an interface that o implements. 이러한 조건에 해당하지 않거나 onull이거나 현재 Type이 개방형 제네릭 형식(즉, ContainsGenericParameterstrue 반환)이면 false입니다.false if neither of these conditions is the case, if o is null, or if the current Type is an open generic type (that is, ContainsGenericParameters returns true).

구현

예제

다음 예제에서는 IsInstanceOfType 메서드를 사용하는 방법을 보여 줍니다.The following example demonstrates the use of the IsInstanceOfType method.

using namespace System;

public interface class IExample{};

public ref class BaseClass: IExample{};

public ref class DerivedClass: BaseClass{};

void main()
{
   Type^ interfaceType = IExample::typeid;
   BaseClass^ base1 = gcnew BaseClass;
   Type^ base1Type = base1->GetType();
   BaseClass^ derived1 = gcnew DerivedClass;
   Type^ derived1Type = derived1->GetType();
   array<Int32>^ arr = gcnew array<Int32>(11);
   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 BaseClass? {0}.",
                      base1Type->IsInstanceOfType( base1 ) );
   Console::WriteLine("Is myderivedclass an instance of BaseClass? {0}.",
                      base1Type->IsInstanceOfType( derived1 ) );
   Console::WriteLine("Is myclass an instance of IExample? {0}.",
                      interfaceType->IsInstanceOfType( base1 ) );
   Console::WriteLine("Is myderivedclass an instance of IExample? {0}.",
                      interfaceType->IsInstanceOfType( derived1 ) );
}
// The example displays the following output:
//    Is int[] an instance of the Array class? True.
//    Is base1 an instance of BaseClass? True.
//    Is derived1 an instance of BaseClass? True.
//    Is base1 an instance of IExample? True.
//    Is derived1 an instance of IExample? True.
using System;

public interface IExample {}

public class BaseClass : IExample {}

public class DerivedClass : BaseClass {}

public class Example
{
    public static void Main()
    {
        var interfaceType = typeof(IExample);
        var base1 = new BaseClass();
        var base1Type = base1.GetType();
        var derived1 = new DerivedClass();
        var derived1Type = derived1.GetType();
        int[] arr = new int[11];

        Console.WriteLine("Is int[] an instance of the Array class? {0}.",
                           typeof(Array).IsInstanceOfType(arr));
        Console.WriteLine("Is base1 an instance of BaseClass? {0}.",
                          base1Type.IsInstanceOfType(base1));
        Console.WriteLine("Is derived1 an instance of BaseClass? {0}.",
                          base1Type.IsInstanceOfType(derived1));
        Console.WriteLine("Is base1 an instance of IExample? {0}.",
                          interfaceType.IsInstanceOfType(base1));
        Console.WriteLine("Is derived1 an instance of IExample? {0}.",
                          interfaceType.IsInstanceOfType(derived1));
    }
}
// The example displays the following output:
//    Is int[] an instance of the Array class? True.
//    Is base1 an instance of BaseClass? True.
//    Is derived1 an instance of BaseClass? True.
//    Is base1 an instance of IExample? True.
//    Is derived1 an instance of IExample? True.
Public Interface IExample
End Interface

Public Class BaseClass : Implements IExample
End Class

Public Class DerivedClass : Inherits BaseClass
End Class

Public Module Example
    Public Sub Main()
        Dim interfaceType As Type = GetType(IExample)
        Dim base1 As New BaseClass()
        Dim base1Type As Type = base1.GetType()
        Dim derived1 = New DerivedClass()
        Dim derived1Type As Type = derived1.GetType()
        Dim arr(10) As Integer

        Console.WriteLine("Is int[] an instance of the Array class? {0}.",
                           GetType(Array).IsInstanceOfType(arr))
        Console.WriteLine("Is base1 an instance of BaseClass? {0}.",
                          base1Type.IsInstanceOfType(base1))
        Console.WriteLine("Is derived1 an instance of BaseClass? {0}.",
                          base1Type.IsInstanceOfType(derived1))
        Console.WriteLine("Is base1 an instance of IExample? {0}.",
                          interfaceType.IsInstanceOfType(base1))
        Console.WriteLine("Is derived1 an instance of IExample? {0}.",
                          interfaceType.IsInstanceOfType(derived1))
    End Sub
End Module
' The example displays the following output:
'    Is int[] an instance of the Array class? True.
'    Is base1 an instance of BaseClass? True.
'    Is derived1 an instance of BaseClass? True.
'    Is base1 an instance of IExample? True.
'    Is derived1 an instance of IExample? True.

설명

이 메서드는 파생된 클래스에서 재정의할 수 있습니다.This method can be overridden by a derived class.

참고

생성된 된 형식을 해당 제네릭 형식 정의의 인스턴스가 아닙니다.A constructed type is not an instance of its generic type definition. 즉, MyGenericList<int> (MyGenericList(Of Integer) Visual basic에서)의 인스턴스가 아닙니다 MyGenericList<T> (MyGenericList(Of T) Visual basic에서).That is, MyGenericList<int> (MyGenericList(Of Integer) in Visual Basic) is not an instance of MyGenericList<T> (MyGenericList(Of T) in Visual Basic).

적용 대상