TypeReference Class

A type used by the code: in a signature, an attribute, or an instruction. The type may be defined outside the architecture.

public sealed class TypeReference

Properties

NameDescription
ArrayRankGets the rank of an array, or 0.
AssemblyNameGets the simple name of the assembly the type is referenced from, or null when it is unknown. Type forwarders are not followed: a type of the framework is often referenced from System.Runtime.
DeclaringTypeGets the containing type of a nested type.
DefinitionGets the definition of a named type when one of the assemblies of the architecture defines it, or null.
ElementTypeGets the element type of an array, a pointer or a reference.
FullNameGets the full name of a named type as written in metadata (System.Collections.Generic.List`1, MyApp.Outer+Inner), without its generic arguments. For other kinds, it is the same as TypeReference.ToString.
GenericArgumentsGets the generic arguments of a generic instantiation (List<Order>), or an empty list.
GenericTypeDefinitionGets the generic type definition of a generic instantiation (List<T> for List<Order>), or null.
IsGenericInstanceGets a value indicating whether the type is a generic instantiation (List<Order>).
KindGets the shape of the type.
MetadataNameGets the name of the type as written in metadata, with the generic arity (List`1).
NameGets the name of the type, without the namespace, the containing type and the generic arity (List).
NamespaceGets the namespace of the type, or of its outermost containing type for a nested type. It is empty for a type that is not named.
SignatureTypesGets the types of the signature of a function pointer (the return type first), or an empty list.

Gets the rank of an array, or 0.

public int ArrayRank { get; }

Property value

int

AssemblyName

TypeReference.cs

Gets the simple name of the assembly the type is referenced from, or null when it is unknown. Type forwarders are not followed: a type of the framework is often referenced from System.Runtime.

public string? AssemblyName { get; }

Property value

string?

DeclaringType

TypeReference.cs

Gets the containing type of a nested type.

public TypeReference? DeclaringType { get; }

Property value

TypeReference?

Gets the definition of a named type when one of the assemblies of the architecture defines it, or null.

public TypeElement? Definition { get; }

Property value

TypeElement?

ElementType

TypeReference.cs

Gets the element type of an array, a pointer or a reference.

public TypeReference? ElementType { get; }

Property value

TypeReference?

Gets the full name of a named type as written in metadata (System.Collections.Generic.List`1, MyApp.Outer+Inner), without its generic arguments. For other kinds, it is the same as TypeReference.ToString.

public string FullName { get; }

Property value

string

GenericArguments

TypeReference.cs

Gets the generic arguments of a generic instantiation (List<Order>), or an empty list.

public IReadOnlyList<TypeReference> GenericArguments { get; }

GenericTypeDefinition

TypeReference.cs

Gets the generic type definition of a generic instantiation (List<T> for List<Order>), or null.

public TypeReference? GenericTypeDefinition { get; }

Property value

TypeReference?

IsGenericInstance

TypeReference.cs

Gets a value indicating whether the type is a generic instantiation (List<Order>).

public bool IsGenericInstance { get; }

Property value

bool

Gets the shape of the type.

public TypeReferenceKind Kind { get; }

Property value

TypeReferenceKind

MetadataName

TypeReference.cs

Gets the name of the type as written in metadata, with the generic arity (List`1).

public string MetadataName { get; }

Property value

string

Gets the name of the type, without the namespace, the containing type and the generic arity (List).

public string Name { get; }

Property value

string

Gets the namespace of the type, or of its outermost containing type for a nested type. It is empty for a type that is not named.

public string Namespace { get; }

Property value

string

SignatureTypes

TypeReference.cs

Gets the types of the signature of a function pointer (the return type first), or an empty list.

public IReadOnlyList<TypeReference> SignatureTypes { get; }

Methods

NameDescription
Is(Type)Determines whether the type is the named type type, or a generic instantiation of it.
Is<T>()Determines whether the type is the named type T, or a generic instantiation of it.
IsInNamespace(string)Determines whether the type is in the namespace namespace, not in one of its child namespaces.
IsInNamespaceOrChildren(string)Determines whether the type is in the namespace namespace or in one of its child namespaces: MyApp.Domain matches MyApp.Domain and MyApp.Domain.Events, not MyApp.DomainEvents.
ToString()Returns the type as written in C#: System.Collections.Generic.List<MyApp.Order>, System.Collections.Generic.List<>.

Is overloads

Determines whether the type is the named type type, or a generic instantiation of it.

public bool Is(Type type)
Parameters
type Type
The named type, or a generic type definition (typeof(List<>)).
Returns

bool true when the full names match.

Determines whether the type is the named type T, or a generic instantiation of it.

public bool Is<T>()
Type parameters
T
The named type.
Returns

bool true when the full names match.

IsInNamespace(string)

TypeReference.cs

Determines whether the type is in the namespace namespace, not in one of its child namespaces.

public bool IsInNamespace(string @namespace)

Parameters

namespace string
The namespace (MyApp.Domain).

Returns

bool true when TypeReference.Namespace is namespace.

See also

IsInNamespaceOrChildren(string)

TypeReference.cs

Determines whether the type is in the namespace namespace or in one of its child namespaces: MyApp.Domain matches MyApp.Domain and MyApp.Domain.Events, not MyApp.DomainEvents.

public bool IsInNamespaceOrChildren(string @namespace)

Parameters

namespace string
The namespace (MyApp.Domain).

Returns

bool true when TypeReference.Namespace is namespace or starts with namespace followed by a dot.

See also

Returns the type as written in C#: System.Collections.Generic.List<MyApp.Order>, System.Collections.Generic.List<>.

public override string ToString()

Returns

string The type as written in C#.