System.Type
Namespace: System
Represents type declarations.
Members
Properties
Assembly
public System.Reflection.Assembly Assembly { get; }
FullName
public string FullName { get; }
IsAbstract
public bool IsAbstract { get; }
IsClass
public bool IsClass { get; }
IsEnum
public bool IsEnum { get; }
IsInterface
public bool IsInterface { get; }
IsPublic
public bool IsPublic { get; }
IsValueType
public bool IsValueType { get; }
Name
public string Name { get; }
Namespace
public string Namespace { get; }
Methods
Equals
public bool Equals(object obj)
Equals
public bool Equals(Type o)
GetConstructor
public System.Reflection.ConstructorInfo GetConstructor(Type[] types)
GetConstructors
public System.Reflection.ConstructorInfo[] GetConstructors(System.Reflection.BindingFlags bindingAttr)
GetEvent
public System.Reflection.EventInfo GetEvent(string name)
GetEvents
public System.Reflection.EventInfo[] GetEvents()
GetField
public System.Reflection.FieldInfo GetField(string name)
GetFields
public System.Reflection.FieldInfo[] GetFields(System.Reflection.BindingFlags bindingAttr)
GetInterface
public System.Type GetInterface(string name)
GetInterfaces
public System.Type[] GetInterfaces()
GetMethod
public System.Reflection.MethodInfo GetMethod(string name)
GetMethods
public System.Reflection.MethodInfo[] GetMethods(System.Reflection.BindingFlags bindingAttr)
GetNestedType
public System.Type GetNestedType(string name)
GetNestedTypes
public System.Type[] GetNestedTypes(System.Reflection.BindingFlags bindingAttr)
GetProperties
public System.Reflection.PropertyInfo[] GetProperties(System.Reflection.BindingFlags bindingAttr)
GetType
public static System.Type GetType(string typeName)
IsAssignableFrom
public bool IsAssignableFrom(System.Type c)
IsInstanceOfType
public bool IsInstanceOfType(object o)
IsSubclassOf
public bool IsSubclassOf(System.Type c)
Static Methods
GetTypeFromHandle
public static System.Type GetTypeFromHandle(System.RuntimeTypeHandle handle)
Remarks
The `System.Type` class is the entry point for inspecting metadata. You can use `Type` objects to discover information about a type, such as its members (methods, properties, fields), attributes, and base types. It's a fundamental part of .NET reflection.
Examples
// Get the Type object for the string class
var stringType = typeof(string);
// Get the full name of the type
Console.WriteLine($"Full Name: {stringType.FullName}"); // Output: Full Name: System.String
// Check if it's a value type
Console.WriteLine($"Is Value Type: {stringType.IsValueType}"); // Output: Is Value Type: False
// Get all public methods
var methods = stringType.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
Console.WriteLine($"Number of public methods: {methods.Length}");
// Get the Type object for the current type (MyClass)
var myClassType = typeof(MyClass);
// Get the namespace
Console.WriteLine($"Namespace: {myClassType.Namespace}");
// Check if it's an abstract class
Console.WriteLine($"Is Abstract: {myClassType.IsAbstract}");
// Get the base type
var baseType = myClassType.BaseType;
if (baseType != null) {
Console.WriteLine($"Base Type: {baseType.FullName}");
}