.NET API Reference

System.Type Class

Namespace: System

Assembly: System.Private.CoreLib.dll

Summary

Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.

Inheritance

System.Object → System.Type

Properties

PropertyTypeDescription
AssemblySystem.Reflection.AssemblyGets the assembly in which the type is declared.
BaseTypeSystem.TypeGets the type from which the current type directly inherits.
FullNamestringGets the fully qualified name of the type, including the namespace.
IsAbstractboolGets a value indicating whether the type is abstract.
IsClassboolGets a value indicating whether the type is a class.
IsEnumboolGets a value indicating whether the type is an enumeration.
IsInterfaceboolGets a value indicating whether the type is an interface.
IsValueTypeboolGets a value indicating whether the type is a value type.
NamestringGets the name of the current type.
NamespacestringGets the namespace of the type.
UnderlyingSystemTypeSystem.TypeGets the underlying system type for the current Type.

Methods

MethodSignatureDescription
GetMethod MethodInfo GetMethod(string name) Retrieves a public method with the specified name.
GetMethods MethodInfo[] GetMethods() Retrieves all public methods of the current type.
GetProperty PropertyInfo GetProperty(string name) Retrieves a public property with the specified name.
GetProperties PropertyInfo[] GetProperties() Retrieves all public properties of the current type.
IsSubclassOf bool IsSubclassOf(Type c) Determines whether the current type derives from the specified type.
IsAssignableFrom bool IsAssignableFrom(Type c) Determines whether an instance of the specified type can be assigned to a variable of the current type.
GetCustomAttributes object[] GetCustomAttributes(bool inherit) Gets an array of custom attributes applied to this member.
ToString override string ToString() Returns the fully qualified name of the type.
MakeGenericType Type MakeGenericType(Type[] typeArguments) Creates a generic type from the current generic type definition and the supplied type arguments.

Example

using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        Type t = typeof(Program);
        Console.WriteLine($"Full name: {t.FullName}");
        Console.WriteLine($"Is class: {t.IsClass}");
        Console.WriteLine($"Assembly: {t.Assembly.GetName().Name}");

        foreach (MethodInfo m in t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
        {
            Console.WriteLine($"Method: {m.Name}");
        }
    }
}

See Also