Class TypeExtensions
A collection of extension and helper methods that simplify working with types.
Inheritance
Inherited Members
Namespace: Flame
Assembly: Flame.dll
Syntax
public static class TypeExtensions
Methods
| Improve this Doc View SourceGetAllInstanceFields(IType)
Gets all fields present in an instance of a particular type. Such fields can either be defined directly or inherited from base types.
Declaration
public static IEnumerable<IField> GetAllInstanceFields(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | A type to inspect. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IField> | A sequence of instance fields. |
GetDefiningAssemblyOrNull(IType)
Gets a type's defining assembly, if one can be found.
Declaration
public static IAssembly GetDefiningAssemblyOrNull(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type to examine. |
Returns
Type | Description |
---|---|
IAssembly | The type's defining assembly, if it has one; otherwise, |
GetDefiningAssemblyOrNull(ITypeMember)
Gets a type member's defining assembly, if one can be found.
Declaration
public static IAssembly GetDefiningAssemblyOrNull(this ITypeMember member)
Parameters
Type | Name | Description |
---|---|---|
ITypeMember | member | The type member to examine. |
Returns
Type | Description |
---|---|
IAssembly | The type member's defining assembly, if it has one; otherwise, |
GetGenericArguments(IMethod)
Gets the generic arguments given to a particular method, if any. The list returned by this method does not include arguments given to parent types of the provided method.
Declaration
public static IReadOnlyList<IType> GetGenericArguments(this IMethod method)
Parameters
Type | Name | Description |
---|---|---|
IMethod | method |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IType> | A list of generic argument types. |
GetGenericArguments(IType)
Gets the generic arguments given to a particular type, if any. The list returned by this method does not include arguments given to parent types of the provided type.
Declaration
public static IReadOnlyList<IType> GetGenericArguments(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IType> | A list of generic argument types. |
GetImplementationOf(IType, IMethod)
Gets most derived implementation of a particular method in a type.
Declaration
public static IMethod GetImplementationOf(this IType type, IMethod method)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type that implements the method. |
IMethod | method | A method to find a more derived implementation for. |
Returns
Type | Description |
---|---|
IMethod | A direct or indirect implementation of |
GetRecursiveGenericArgumentMapping(IMethod)
Creates a dictionary that maps a method's recursive generic parameters to their arguments. Additionally, original generic parameters are also mapped to modified generic parameters.
Declaration
public static IReadOnlyDictionary<IType, IType> GetRecursiveGenericArgumentMapping(this IMethod method)
Parameters
Type | Name | Description |
---|---|---|
IMethod | method | The method to create the mapping for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyDictionary<IType, IType> | A mapping of generic parameters to their arguments. |
GetRecursiveGenericArgumentMapping(IType)
Creates a dictionary that maps a type's recursive generic parameters to their arguments. Additionally, original generic parameters are also mapped to modified generic parameters.
Declaration
public static IReadOnlyDictionary<IType, IType> GetRecursiveGenericArgumentMapping(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type to create the mapping for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyDictionary<IType, IType> | A mapping of generic parameters to their arguments. |
GetRecursiveGenericArguments(IType)
Gets the recursive generic arguments for a particular type.
Declaration
public static IReadOnlyList<IType> GetRecursiveGenericArguments(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | A type to examine. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IType> | The type's list of recursive generic arguments. |
GetRecursiveGenericDeclaration(IField)
Gets the recursive generic declaration of a field.
If the field is not a recursive generic instance, the field itself is returned.
If the field is a recursive generic instance, the recursive generic declaration of the field's generic declaration is returned.
Declaration
public static IField GetRecursiveGenericDeclaration(this IField field)
Parameters
Type | Name | Description |
---|---|---|
IField | field | A field to examine. |
Returns
Type | Description |
---|---|
IField | The field's recursive generic declaration. |
GetRecursiveGenericDeclaration(IMethod)
Gets the recursive generic declaration of a method.
If the method is not a recursive generic instance, the method itself is returned.
If the method is a recursive generic instance, the recursive generic declaration of the method's generic declaration is returned.
Declaration
public static IMethod GetRecursiveGenericDeclaration(this IMethod method)
Parameters
Type | Name | Description |
---|---|---|
IMethod | method | A method to examine. |
Returns
Type | Description |
---|---|
IMethod | The method's recursive generic declaration. |
GetRecursiveGenericDeclaration(IType)
Gets the recursive generic declaration of a type.
If the type is not a recursive generic instance, the type itself is returned.
If the type is a recursive generic instance, the recursive generic declaration of the type's generic declaration is returned.
Declaration
public static IType GetRecursiveGenericDeclaration(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | A type to examine. |
Returns
Type | Description |
---|---|
IType | The type's recursive generic declaration. |
GetRecursiveGenericParameters(IType)
Gets the recursive generic parameters for a particular type.
Declaration
public static IReadOnlyList<IGenericParameter> GetRecursiveGenericParameters(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | A type to examine. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<IGenericParameter> | The type's list of recursive generic parameters. |
IsPointerType(IType)
Tests if a type is a pointer type.
Declaration
public static bool IsPointerType(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type to inspect. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsPointerType(IType, PointerKind)
Tests if a type is a pointer type of a particular kind.
Declaration
public static bool IsPointerType(this IType type, PointerKind kind)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type to inspect. |
PointerKind | kind | The kind of pointer to test for. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsRecursiveGenericInstance(IType)
Tells if a particular type is either a generic instance or a nested type of a generic instance.
Declaration
public static bool IsRecursiveGenericInstance(this IType type)
Parameters
Type | Name | Description |
---|---|---|
IType | type | A type to examine. |
Returns
Type | Description |
---|---|
System.Boolean |
|
MakeGenericMethod(IMethod, IType[])
Creates a generic specialization of a particular generic method declaration
Declaration
public static DirectMethodSpecialization MakeGenericMethod(this IMethod declaration, params IType[] genericArguments)
Parameters
Type | Name | Description |
---|---|---|
IMethod | declaration | The generic method declaration that is specialized into a concrete method. |
IType[] | genericArguments | The type arguments with which the generic method is specialized. |
Returns
Type | Description |
---|---|
DirectMethodSpecialization | A generic specialization. |
MakeGenericMethod(IMethod, IReadOnlyList<IType>)
Creates a generic specialization of a particular generic method declaration
Declaration
public static DirectMethodSpecialization MakeGenericMethod(this IMethod declaration, IReadOnlyList<IType> genericArguments)
Parameters
Type | Name | Description |
---|---|---|
IMethod | declaration | The generic method declaration that is specialized into a concrete method. |
System.Collections.Generic.IReadOnlyList<IType> | genericArguments | The type arguments with which the generic method is specialized. |
Returns
Type | Description |
---|---|
DirectMethodSpecialization | A generic specialization. |
MakeGenericType(IType, IType[])
Creates a generic specialization of a particular generic type declaration
Declaration
public static DirectTypeSpecialization MakeGenericType(this IType declaration, params IType[] genericArguments)
Parameters
Type | Name | Description |
---|---|---|
IType | declaration | The generic type declaration that is specialized into a concrete type. |
IType[] | genericArguments | The type arguments with which the generic type is specialized. |
Returns
Type | Description |
---|---|
DirectTypeSpecialization | A generic specialization. |
MakeGenericType(IType, IReadOnlyList<IType>)
Creates a generic specialization of a particular generic type declaration
Declaration
public static DirectTypeSpecialization MakeGenericType(this IType declaration, IReadOnlyList<IType> genericArguments)
Parameters
Type | Name | Description |
---|---|---|
IType | declaration | The generic type declaration that is specialized into a concrete type. |
System.Collections.Generic.IReadOnlyList<IType> | genericArguments | The type arguments with which the generic type is specialized. |
Returns
Type | Description |
---|---|
DirectTypeSpecialization | A generic specialization. |
MakePointerType(IType, PointerKind)
Creates a pointer type of a particular kind that has a type as element.
Declaration
public static PointerType MakePointerType(this IType type, PointerKind kind)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type of values referred to by the pointer type. |
PointerKind | kind | The kind of the pointer type. |
Returns
Type | Description |
---|---|
PointerType | A pointer type. |
MakeRecursiveGenericType(IType, IReadOnlyList<IType>)
Turns a recursive generic declaration into a recursive generic instance with a particular list of recursive generic arguments.
Declaration
public static IType MakeRecursiveGenericType(this IType type, IReadOnlyList<IType> recursiveGenericArguments)
Parameters
Type | Name | Description |
---|---|---|
IType | type | The type to recursively instantiate. |
System.Collections.Generic.IReadOnlyList<IType> | recursiveGenericArguments | A list of recursive generic arguments for the type. |
Returns
Type | Description |
---|---|
IType | A recursive generic instance type. |