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
Property | Type | Description |
---|---|---|
Assembly | System.Reflection.Assembly | Gets the assembly in which the type is declared. |
BaseType | System.Type | Gets the type from which the current type directly inherits. |
FullName | string | Gets the fully qualified name of the type, including the namespace. |
IsAbstract | bool | Gets a value indicating whether the type is abstract. |
IsClass | bool | Gets a value indicating whether the type is a class. |
IsEnum | bool | Gets a value indicating whether the type is an enumeration. |
IsInterface | bool | Gets a value indicating whether the type is an interface. |
IsValueType | bool | Gets a value indicating whether the type is a value type. |
Name | string | Gets the name of the current type. |
Namespace | string | Gets the namespace of the type. |
UnderlyingSystemType | System.Type | Gets the underlying system type for the current Type . |
Methods
Method | Signature | Description |
---|---|---|
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}");
}
}
}