Class ReflectionHelper
Helper methods for reflection.
Inherited Members
Namespace: Evergine.Common.Helpers
Assembly: Evergine.Common.dll
Syntax
public static class ReflectionHelper
Methods
FindTypes(Assembly, Func<Type, bool>)
Find the types that match the corresponding predicate.
Declaration
public static IEnumerable<Type> FindTypes(Assembly assembly, Func<Type, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | The target search assembly. |
Func<Type, bool> | predicate | The predicate to filter types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A collection of matching types. |
GetBaseType(Type)
Gets the type from which the current System.Type directly inherits.
Declaration
public static Type GetBaseType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
Type | The Type from which the current System.Type directly inherits, or null if the current Type represents the System.Object class or an interface. |
GetFullNameWithoutAssemblyInfo(Type)
Gets the full name of the name of the specified type without assembly full name.
Declaration
public static string GetFullNameWithoutAssemblyInfo(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
string | The full name of the name without assembly full name. |
GetGenericTypeDefinition(Type)
Returns a Type object that represents a generic type definition from which the current generic type can be constructed.
Declaration
public static Type GetGenericTypeDefinition(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
Type | A Type object representing a generic type from which the current type can be constructed. |
GetInterfaces(Type)
Gets the interfaces.
Declaration
public static Type[] GetInterfaces(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
Type[] | The interfaces. |
GetMemberAssembly(object)
Gets the Assembly in which the member type is declared. For generic types, gets the Assembly in which the generic type is defined.
Declaration
public static Assembly GetMemberAssembly(this object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The member. |
Returns
Type | Description |
---|---|
Assembly | The type assembly. |
GetSizeOf<T>()
Gets the size of the specified type.
Declaration
public static int GetSizeOf<T>()
Returns
Type | Description |
---|---|
int | The size of the specified type. |
Type Parameters
Name | Description |
---|---|
T | The type. |
GetTypeAssembly(Type)
Gets the Assembly in which the type is declared. For generic types, gets the Assembly in which the generic type is defined.
Declaration
public static Assembly GetTypeAssembly(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
Assembly | The type assembly. |
GetTypeAssemblyName(Type)
Gets the Assembly name in which the type is declared. For generic types, gets the Assembly name in which the generic type is defined.
Declaration
public static string GetTypeAssemblyName(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
string | A string containing the name of this member assembly. |
GetTypeName(object)
Gets the name of the current member.
Declaration
public static string GetTypeName(this object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object. |
Returns
Type | Description |
---|---|
string | A string containing the name of this member type. |
IsAssignableFrom(Type, Type)
Determines whether an instance of the second specified type can be assigned to the first specified type instance.
Declaration
public static bool IsAssignableFrom(this Type first, Type second)
Parameters
Type | Name | Description |
---|---|---|
Type | first | The first type. |
Type | second | The type to check. |
Returns
Type | Description |
---|---|
bool |
|
IsAttributeDefined<TAttribute>(Type)
Indicates whether custom attributes of a specified type are applied to a specified type.
Declaration
public static bool IsAttributeDefined<TAttribute>(this Type type) where TAttribute : Attribute
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
TAttribute | The type of the attribute. |
IsCastableFrom(Type, Type)
Determines whether an instance of the second specified type can be casted to the first specified type instance.
Declaration
public static bool IsCastableFrom(this Type first, Type second)
Parameters
Type | Name | Description |
---|---|---|
Type | first | The first type. |
Type | second | The type to check. |
Returns
Type | Description |
---|---|
bool |
|
IsEnum(Type)
Determines whether the specified Type is enum.
Declaration
public static bool IsEnum(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
IsGenericType(Type)
Gets a value indicating whether the specified Type is a generic type.
Declaration
public static bool IsGenericType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
IsGenericTypeDefinition(Type)
Gets a value indicating whether the specified type is a generic type definition.
Declaration
public static bool IsGenericTypeDefinition(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
IsInterface(Type)
Determines whether the specified type is an interface.
Declaration
public static bool IsInterface(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
IsPrimitive(Type)
Determines whether the specified Type is one of the primitive types.
Declaration
public static bool IsPrimitive(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|
IsValueType(Type)
Gets a value indicating whether the specified type is a value type.
Declaration
public static bool IsValueType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool |
|