Type.IsSubclassOf(Type) 메서드

정의

현재 Type 지정된 Type파생되는지 여부를 확인합니다.

public:
 virtual bool IsSubclassOf(Type ^ c);
public virtual bool IsSubclassOf(Type c);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual bool IsSubclassOf(Type c);
abstract member IsSubclassOf : Type -> bool
override this.IsSubclassOf : Type -> bool
[<System.Runtime.InteropServices.ComVisible(true)>]
abstract member IsSubclassOf : Type -> bool
override this.IsSubclassOf : Type -> bool
Public Overridable Function IsSubclassOf (c As Type) As Boolean

매개 변수

c
Type

현재 형식과 비교할 형식입니다.

반품

true 현재 Type 가 파생 c되면 ;이고, false그렇지 않으면 . 또한 이 메서드는 현재 false 값이 같은 경우 c 를 반환 Type 합니다.

구현

특성

예외

cnull입니다.

예제

다음 예제에서는 명명된 클래스와 이름이 Class1DerivedC1지정된 파생 클래스를 만듭니다. 메서드를 IsSubclassOf 호출하여 해당 메서드가 .의 DerivedC1하위 클래스임을 Class1 표시합니다.

using System;

public class Class1 { }
public class DerivedC1 : Class1 { }

class IsSubclassTest
{
   public static void Main()
   {
      Console.WriteLine("DerivedC1 subclass of Class1: {0}",
                         typeof(DerivedC1).IsSubclassOf(typeof(Class1)));
   }
}
// The example displays the following output:
//        DerivedC1 subclass of Class1: True
type Class1() = class end
type DerivedC1() = inherit Class1()

printfn $"DerivedC1 subclass of Class1: {typeof<DerivedC1>.IsSubclassOf typeof<Class1>}"

// The example displays the following output:
//        DerivedC1 subclass of Class1: True
Public Class Class1
End Class

Public Class DerivedC1 : Inherits Class1
End Class

Public Module Example
   Public Sub Main()
      Console.WriteLine("DerivedC1 subclass of Class1: {0}",
                         GetType(DerivedC1).IsSubClassOf(GetType(Class1)))
   End Sub
End Module
' The example displays the following output:
'       DerivedC1 subclass of Class1: True

설명

메서드를 IsSubclassOf 호출하여 다음 중 어느 것을 확인할 수 있습니다.

  • 한 클래스가 다른 클래스에서 파생되는지 여부입니다.

  • 형식이 .에서 ValueType파생되는지 여부입니다. 그러나 형식이 IsValueType 값 형식인지 여부를 확인하는 보다 효율적인 방법입니다.

  • 형식이 .에서 Enum파생되는지 여부입니다. 그러나 IsEnum 이 메서드는 형식이 열거형인지 여부를 확인하는 보다 효율적인 방법입니다.

  • 형식이 대리자인지 여부, 즉 대리자에서 DelegateMulticastDelegate파생되는지 여부입니다.

이 메서드는 IsSubclassOf 인터페이스가 다른 인터페이스에서 파생되는지 또는 클래스가 인터페이스를 구현하는지 여부를 결정하는 데 사용할 수 없습니다. IsAssignableFrom 다음 예제와 같이 해당 용도로 메서드를 사용합니다.

using System;

public interface IInterface
{
   void Display();
}

public class Implementation : IInterface
{
   public void Display()
   {
      Console.WriteLine("The implementation...");
   }
}

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Implementation is a subclass of IInterface:   {0}",
                        typeof(Implementation).IsSubclassOf(typeof(IInterface)));
      Console.WriteLine("IInterface is assignable from Implementation: {0}",
                        typeof(IInterface).IsAssignableFrom(typeof(Implementation)));
   }
}
// The example displays the following output:
//       Implementation is a subclass of IInterface:   False
//       IInterface is assignable from Implementation: True
type IInterface =
    abstract Display : unit -> unit

type Implementation() =
    interface IInterface with
        member _.Display() = printfn "The implementation..."

printfn $"Implementation is a subclass of IInterface:   {typeof<Implementation>.IsSubclassOf typeof<IInterface>}"
printfn $"IInterface is assignable from Implementation: {typeof<IInterface>.IsAssignableFrom typeof<Implementation>}"
// The example displays the following output:
//       Implementation is a subclass of IInterface:   False
//       IInterface is assignable from Implementation: True
Public Interface IInterface
   Sub Display()
End Interface

Public Class Implementation : Implements IInterface
   Public Sub Display() _
      Implements IInterface.Display

      Console.WriteLine("The implementation...")
   End Sub
End Class

Module Example
   Public Sub Main()
      Console.WriteLine("Implementation is a subclass of IInterface:   {0}",
                        GetType(Implementation).IsSubclassOf(GetType(IInterface)))
      Console.WriteLine("IInterface is assignable from Implementation: {0}",
                        GetType(IInterface).IsAssignableFrom(GetType(Implementation)))
   End Sub
End Module
' The example displays the following output:
'       Implementation is a subclass of IInterface:   False
'       IInterface is assignable from Implementation: True

현재 Type 제네릭 형식 또는 제네릭 메서드의 정의에서 형식 매개 변수를 나타내는 경우 클래스 제약 조건 또는 System.Object 클래스 제약 조건이 없는 경우 파생됩니다.

메모

인터페이스와 함께 사용되는 경우를 제외하고, IsSubclassOf 의 반대 IsAssignableFrom입니다. 즉, if t1.IsSubclassOf(t2) is, truethen t2.IsAssignableFrom(t1)true있습니다.

이 메서드는 파생 클래스에서 재정의할 수 있습니다.

적용 대상

추가 정보