C# Class ICSharpCode.NRefactory.TypeSystem.TypeSystemExtensions

Contains extension methods for the type system.
Show file Open project: icsharpcode/NRefactory

Public Methods

Method Description
CreateResolvedAttributes ( this attributes, ITypeResolveContext context ) : IList
CreateResolvedParameters ( this parameters, ITypeResolveContext context ) : IList
CreateResolvedTypeParameters ( this typeParameters, ITypeResolveContext context ) : IList
FindType ( this compilation, FullTypeName fullTypeName ) : IType

Retrieves the specified type in this compilation. Returns an UnknownType if the type cannot be found in this compilation.

There can be multiple types with the same full name in a compilation, as a full type name is only unique per assembly. If there are multiple possible matches, this method will return just one of them. When possible, use IAssembly.GetTypeDefinition instead to retrieve a type from a specific assembly.

GetAllBaseTypeDefinitions ( this type ) : IEnumerable

Gets all base type definitions. The output is ordered so that base types occur before derived types.

This is equivalent to type.GetAllBaseTypes().Select(t => t.GetDefinition()).Where(d => d != null).Distinct().

GetAllBaseTypes ( this type ) : IEnumerable

Gets all base types.

This is the reflexive and transitive closure of IType.DirectBaseTypes. Note that this method does not return all supertypes - doing so is impossible due to contravariance (and undesirable for covariance as the list could become very large). The output is ordered so that base types occur before derived types.

GetAllTypeDefinitions ( this assembly ) : IEnumerable
GetAllTypeDefinitions ( this file ) : IEnumerable

Gets all unresolved type definitions from the file. For partial classes, each part is returned.

GetAttribute ( this entity, FullTypeName attributeType, bool inherit = true ) : IAttribute

Gets the attribute of the specified attribute type (or derived attribute types).

GetAttribute ( this entity, IType attributeType, bool inherit = true ) : IAttribute

Gets the attribute of the specified attribute type (or derived attribute types).

GetAttributes ( this entity, FullTypeName attributeType, bool inherit = true ) : IEnumerable

Gets the attributes of the specified attribute type (or derived attribute types).

GetAttributes ( this entity, IType attributeType, bool inherit = true ) : IEnumerable

Gets the attributes of the specified attribute type (or derived attribute types).

GetAttributes ( this entity, bool inherit = true ) : IEnumerable

Gets the attribute of the specified attribute type (or derived attribute types).

GetDelegateInvokeMethod ( this type ) : IMethod

Gets the invoke method for a delegate type.

Returns null if the type is not a delegate type; or if the invoke method could not be found.

GetInnermostTypeDefinition ( this file, int line, int column ) : IUnresolvedTypeDefinition

Gets the type (potentially a nested type) defined at the specified location. Returns null if no type is defined at that location.

GetMember ( this file, int line, int column ) : IUnresolvedMember

Gets the member defined at the specified location. Returns null if no member is defined at that location.

GetNonInterfaceBaseTypes ( this type ) : IEnumerable

Gets all non-interface base types.

When type is an interface, this method will also return base interfaces (return same output as GetAllBaseTypes()). The output is ordered so that base types occur before derived types.

GetSubTypeDefinitions ( this baseType ) : IEnumerable
GetSymbol ( this rr ) : ISymbol
GetTopLevelTypeDefinitons ( this compilation ) : IEnumerable

Gets all top level type definitions in the compilation. This may include types from referenced assemblies that are not accessible in the main assembly.

GetTypeDefinition ( this assembly, FullTypeName fullTypeName ) : ITypeDefinition

Gets the type definition for the specified unresolved type. Returns null if the unresolved type does not belong to this assembly.

GetTypeDefinition ( this assembly, string namespaceName, string name, int typeParameterCount ) : ITypeDefinition

Gets the type definition for a top-level type.

This method uses ordinal name comparison, not the compilation's name comparer.

Import ( this compilation, IEntity entity ) : IEntity

Imports an entity from another compilation.

Import ( this compilation, IEvent ev ) : IEvent

Imports a member from another compilation.

Import ( this compilation, IField field ) : IField

Imports a member from another compilation.

Import ( this compilation, IMember member ) : IMember

Imports a member from another compilation.

Import ( this compilation, IMethod method ) : IMethod

Imports a member from another compilation.

Import ( this compilation, INamespace ns ) : INamespace

Imports a namespace from another compilation.

This method may return null if the namespace does not exist in the target compilation.

Import ( this compilation, IProperty property ) : IProperty

Imports a member from another compilation.

Import ( this compilation, ISymbol symbol ) : ISymbol

Imports a symbol from another compilation.

Import ( this compilation, IType type ) : IType

Imports a type from another compilation.

Import ( this compilation, ITypeDefinition typeDefinition ) : ITypeDefinition

Imports a type from another compilation.

IsDerivedFrom ( this type, ITypeDefinition baseType ) : bool

Gets whether this type definition is derived from the base type definition.

IsDerivedFrom ( this type, KnownTypeCode baseType ) : bool

Gets whether this type definition is derived from a given known type.

IsKnownType ( this type, KnownTypeCode knownType ) : bool

Gets whether the type is the specified known type. For generic known types, this returns true any parameterization of the type (and also for the definition itself).

IsOpen ( this type ) : bool

Gets whether the type is an open type (contains type parameters).

IsUnbound ( this type ) : bool

Gets whether the type is unbound (is a generic type, but no type arguments were provided).

In "typeof(List<Dictionary<,>>)", only the Dictionary is unbound, the List is considered bound despite containing an unbound type. This method returns false for partially parameterized types (Dictionary<string, >).

Resolve ( this typeReferences, ITypeResolveContext context ) : IList
Resolve ( this constantValues, ITypeResolveContext context ) : IList
Resolve ( this reference, ICompilation compilation ) : IType

Resolves a type reference in the compilation's main type resolve context. Some type references require a more specific type resolve context and will not resolve using this method.

Private Methods

Method Description
FindNestedType ( ITypeDefinition typeDef, string name, int typeParameterCount ) : ITypeDefinition
GetAttributes ( IEntity entity, Predicate attributeTypePredicate, bool inherit ) : IEnumerable
GetTypeParameterOwner ( IType type ) : IEntity

Gets the entity that owns the type parameters occurring in the specified type. If both class and method type parameters are present, the method is returned. Returns null if the specified type is closed.

Method Details

CreateResolvedAttributes() public static method

public static CreateResolvedAttributes ( this attributes, ITypeResolveContext context ) : IList
attributes this
context ITypeResolveContext
return IList

CreateResolvedParameters() public static method

public static CreateResolvedParameters ( this parameters, ITypeResolveContext context ) : IList
parameters this
context ITypeResolveContext
return IList

CreateResolvedTypeParameters() public static method

public static CreateResolvedTypeParameters ( this typeParameters, ITypeResolveContext context ) : IList
typeParameters this
context ITypeResolveContext
return IList

FindType() public static method

Retrieves the specified type in this compilation. Returns an UnknownType if the type cannot be found in this compilation.
There can be multiple types with the same full name in a compilation, as a full type name is only unique per assembly. If there are multiple possible matches, this method will return just one of them. When possible, use IAssembly.GetTypeDefinition instead to retrieve a type from a specific assembly.
public static FindType ( this compilation, FullTypeName fullTypeName ) : IType
compilation this
fullTypeName FullTypeName
return IType

GetAllBaseTypeDefinitions() public static method

Gets all base type definitions. The output is ordered so that base types occur before derived types.
This is equivalent to type.GetAllBaseTypes().Select(t => t.GetDefinition()).Where(d => d != null).Distinct().
public static GetAllBaseTypeDefinitions ( this type ) : IEnumerable
type this
return IEnumerable

GetAllBaseTypes() public static method

Gets all base types.
This is the reflexive and transitive closure of IType.DirectBaseTypes. Note that this method does not return all supertypes - doing so is impossible due to contravariance (and undesirable for covariance as the list could become very large). The output is ordered so that base types occur before derived types.
public static GetAllBaseTypes ( this type ) : IEnumerable
type this
return IEnumerable

GetAllTypeDefinitions() public static method

public static GetAllTypeDefinitions ( this assembly ) : IEnumerable
assembly this
return IEnumerable

GetAllTypeDefinitions() public static method

Gets all unresolved type definitions from the file. For partial classes, each part is returned.
public static GetAllTypeDefinitions ( this file ) : IEnumerable
file this
return IEnumerable

GetAttribute() public static method

Gets the attribute of the specified attribute type (or derived attribute types).
public static GetAttribute ( this entity, FullTypeName attributeType, bool inherit = true ) : IAttribute
entity this The entity on which the attributes are declared.
attributeType FullTypeName The attribute type to look for.
inherit bool /// Specifies whether attributes inherited from base classes and base members (if the given in an override) /// should be returned. The default is true. ///
return IAttribute

GetAttribute() public static method

Gets the attribute of the specified attribute type (or derived attribute types).
public static GetAttribute ( this entity, IType attributeType, bool inherit = true ) : IAttribute
entity this The entity on which the attributes are declared.
attributeType IType The attribute type to look for.
inherit bool /// Specifies whether attributes inherited from base classes and base members (if the given in an override) /// should be returned. The default is true. ///
return IAttribute

GetAttributes() public static method

Gets the attributes of the specified attribute type (or derived attribute types).
public static GetAttributes ( this entity, FullTypeName attributeType, bool inherit = true ) : IEnumerable
entity this The entity on which the attributes are declared.
attributeType FullTypeName The attribute type to look for.
inherit bool /// Specifies whether attributes inherited from base classes and base members (if the given in an override) /// should be returned. The default is true. ///
return IEnumerable

GetAttributes() public static method

Gets the attributes of the specified attribute type (or derived attribute types).
public static GetAttributes ( this entity, IType attributeType, bool inherit = true ) : IEnumerable
entity this The entity on which the attributes are declared.
attributeType IType The attribute type to look for.
inherit bool /// Specifies whether attributes inherited from base classes and base members (if the given in an override) /// should be returned. The default is true. ///
return IEnumerable

GetAttributes() public static method

Gets the attribute of the specified attribute type (or derived attribute types).
public static GetAttributes ( this entity, bool inherit = true ) : IEnumerable
entity this The entity on which the attributes are declared.
inherit bool /// Specifies whether attributes inherited from base classes and base members (if the given in an override) /// should be returned. The default is true. ///
return IEnumerable

GetDelegateInvokeMethod() public static method

Gets the invoke method for a delegate type.
Returns null if the type is not a delegate type; or if the invoke method could not be found.
public static GetDelegateInvokeMethod ( this type ) : IMethod
type this
return IMethod

GetInnermostTypeDefinition() public static method

Gets the type (potentially a nested type) defined at the specified location. Returns null if no type is defined at that location.
public static GetInnermostTypeDefinition ( this file, int line, int column ) : IUnresolvedTypeDefinition
file this
line int
column int
return IUnresolvedTypeDefinition

GetMember() public static method

Gets the member defined at the specified location. Returns null if no member is defined at that location.
public static GetMember ( this file, int line, int column ) : IUnresolvedMember
file this
line int
column int
return IUnresolvedMember

GetNonInterfaceBaseTypes() public static method

Gets all non-interface base types.
When type is an interface, this method will also return base interfaces (return same output as GetAllBaseTypes()). The output is ordered so that base types occur before derived types.
public static GetNonInterfaceBaseTypes ( this type ) : IEnumerable
type this
return IEnumerable

GetSubTypeDefinitions() public static method

public static GetSubTypeDefinitions ( this baseType ) : IEnumerable
baseType this
return IEnumerable

GetSymbol() public static method

public static GetSymbol ( this rr ) : ISymbol
rr this
return ISymbol

GetTopLevelTypeDefinitons() public static method

Gets all top level type definitions in the compilation. This may include types from referenced assemblies that are not accessible in the main assembly.
public static GetTopLevelTypeDefinitons ( this compilation ) : IEnumerable
compilation this
return IEnumerable

GetTypeDefinition() public static method

Gets the type definition for the specified unresolved type. Returns null if the unresolved type does not belong to this assembly.
public static GetTypeDefinition ( this assembly, FullTypeName fullTypeName ) : ITypeDefinition
assembly this
fullTypeName FullTypeName
return ITypeDefinition

GetTypeDefinition() public static method

Gets the type definition for a top-level type.
This method uses ordinal name comparison, not the compilation's name comparer.
public static GetTypeDefinition ( this assembly, string namespaceName, string name, int typeParameterCount ) : ITypeDefinition
assembly this
namespaceName string
name string
typeParameterCount int
return ITypeDefinition

Import() public static method

Imports an entity from another compilation.
public static Import ( this compilation, IEntity entity ) : IEntity
compilation this
entity IEntity
return IEntity

Import() public static method

Imports a member from another compilation.
public static Import ( this compilation, IEvent ev ) : IEvent
compilation this
ev IEvent
return IEvent

Import() public static method

Imports a member from another compilation.
public static Import ( this compilation, IField field ) : IField
compilation this
field IField
return IField

Import() public static method

Imports a member from another compilation.
public static Import ( this compilation, IMember member ) : IMember
compilation this
member IMember
return IMember

Import() public static method

Imports a member from another compilation.
public static Import ( this compilation, IMethod method ) : IMethod
compilation this
method IMethod
return IMethod

Import() public static method

Imports a namespace from another compilation.
This method may return null if the namespace does not exist in the target compilation.
public static Import ( this compilation, INamespace ns ) : INamespace
compilation this
ns INamespace
return INamespace

Import() public static method

Imports a member from another compilation.
public static Import ( this compilation, IProperty property ) : IProperty
compilation this
property IProperty
return IProperty

Import() public static method

Imports a symbol from another compilation.
public static Import ( this compilation, ISymbol symbol ) : ISymbol
compilation this
symbol ISymbol
return ISymbol

Import() public static method

Imports a type from another compilation.
public static Import ( this compilation, IType type ) : IType
compilation this
type IType
return IType

Import() public static method

Imports a type from another compilation.
public static Import ( this compilation, ITypeDefinition typeDefinition ) : ITypeDefinition
compilation this
typeDefinition ITypeDefinition
return ITypeDefinition

IsDerivedFrom() public static method

Gets whether this type definition is derived from the base type definition.
public static IsDerivedFrom ( this type, ITypeDefinition baseType ) : bool
type this
baseType ITypeDefinition
return bool

IsDerivedFrom() public static method

Gets whether this type definition is derived from a given known type.
public static IsDerivedFrom ( this type, KnownTypeCode baseType ) : bool
type this
baseType KnownTypeCode
return bool

IsKnownType() public static method

Gets whether the type is the specified known type. For generic known types, this returns true any parameterization of the type (and also for the definition itself).
public static IsKnownType ( this type, KnownTypeCode knownType ) : bool
type this
knownType KnownTypeCode
return bool

IsOpen() public static method

Gets whether the type is an open type (contains type parameters).
public static IsOpen ( this type ) : bool
type this
return bool

IsUnbound() public static method

Gets whether the type is unbound (is a generic type, but no type arguments were provided).
In "typeof(List<Dictionary<,>>)", only the Dictionary is unbound, the List is considered bound despite containing an unbound type. This method returns false for partially parameterized types (Dictionary<string, >).
public static IsUnbound ( this type ) : bool
type this
return bool

Resolve() public static method

public static Resolve ( this typeReferences, ITypeResolveContext context ) : IList
typeReferences this
context ITypeResolveContext
return IList

Resolve() public static method

public static Resolve ( this constantValues, ITypeResolveContext context ) : IList
constantValues this
context ITypeResolveContext
return IList

Resolve() public static method

Resolves a type reference in the compilation's main type resolve context. Some type references require a more specific type resolve context and will not resolve using this method.
public static Resolve ( this reference, ICompilation compilation ) : IType
reference this
compilation ICompilation
return IType