TypeElement Class

A type defined in an assembly of the architecture.

public sealed class TypeElement

Properties

NameDescription
AccessibilityGets the declared accessibility of the type.
ArchitectureGets the architecture that contains the type.
AssemblyGets the assembly that defines the type.
AttributesGets the attributes applied to the type.
BaseTypeGets the base type, or null for an interface and for Object.
ConstructorsGets the instance and static constructors.
DeclaringTypeGets the containing type of a nested type, or null.
DependenciesGets the types the type uses, in its declaration, the declarations of its members, and the code of its methods, lambdas, local functions, iterators and async methods. A type used several times by a member in the same way gives one dependency. The type itself and the types generated by the compiler are not included.
EventsGets the events.
FieldsGets the fields, except the ones generated by the compiler (backing fields of auto-properties).
FullNameGets the full name of the type as written in metadata (MyApp.Repository`1, MyApp.Outer+Inner), which is also the value of Type.FullName.
GenericParametersGets the names of the generic parameters of the type, including the ones of its containing types.
InterfacesGets the interfaces the type declares. Use TypeElement.Implements to include the interfaces of the base types.
IsAbstractGets a value indicating whether the type is an abstract class. Interfaces and static classes are not abstract classes.
IsClassGets a value indicating whether the type is a class, including a record class.
IsDelegateGets a value indicating whether the type is a delegate.
IsEnumGets a value indicating whether the type is an enum.
IsGenericGets a value indicating whether the type has generic parameters, including the ones of its containing types.
IsImmutableGets a value indicating whether the instances of the type cannot be modified: its instance fields are readonly or constant, and its instance properties have no setter, or an init setter. The types of the fields are not checked.
IsInterfaceGets a value indicating whether the type is an interface.
IsNestedGets a value indicating whether the type is nested in another type.
IsPublicGets a value indicating whether the type is declared public. A public type nested in a non-public type is public.
IsRecordGets a value indicating whether the type is a record class or a record struct.
IsSealedGets a value indicating whether no type can inherit from the type: a sealed class, a struct, an enum or a delegate. Static classes are not sealed.
IsStaticGets a value indicating whether the type is a static class.
IsStructGets a value indicating whether the type is a struct, including a record struct.
KindGets the kind of the type.
LocationGets the first statement of the type when the PDB is available, or null.
MembersGets all the members: constructors, methods, properties, fields and events.
MetadataNameGets the name of the type as written in metadata, with the generic arity (Repository`1).
MethodsGets the methods, except the constructors, the accessors of the properties and events, and the methods generated by the compiler (lambdas, local functions).
NameGets the name of the type, without the namespace, the containing type and the generic arity (Repository for Repository<T>).
NamespaceGets the namespace of the type, or of its outermost containing type for a nested type.
NestedTypesGets the nested types, except the ones generated by the compiler.
PropertiesGets the properties and indexers.

Accessibility

TypeElement.cs

Gets the declared accessibility of the type.

public ElementAccessibility Accessibility { get; }

Property value

ElementAccessibility

Architecture

TypeElement.cs

Gets the architecture that contains the type.

public ArchitectureModel Architecture { get; }

Property value

ArchitectureModel

Gets the assembly that defines the type.

public AssemblyElement Assembly { get; }

Property value

AssemblyElement

Attributes

TypeElement.cs

Gets the attributes applied to the type.

public IReadOnlyList<AttributeElement> Attributes { get; }

Gets the base type, or null for an interface and for Object.

public TypeReference? BaseType { get; }

Property value

TypeReference?

Constructors

TypeElement.cs

Gets the instance and static constructors.

public IReadOnlyList<MethodElement> Constructors { get; }

DeclaringType

TypeElement.cs

Gets the containing type of a nested type, or null.

public TypeElement? DeclaringType { get; }

Property value

TypeElement?

Dependencies

TypeElement.cs

Gets the types the type uses, in its declaration, the declarations of its members, and the code of its methods, lambdas, local functions, iterators and async methods. A type used several times by a member in the same way gives one dependency. The type itself and the types generated by the compiler are not included.

public IReadOnlyList<Dependency> Dependencies { get; }

Gets the events.

public IReadOnlyList<EventElement> Events { get; }

Gets the fields, except the ones generated by the compiler (backing fields of auto-properties).

public IReadOnlyList<FieldElement> Fields { get; }

Gets the full name of the type as written in metadata (MyApp.Repository`1, MyApp.Outer+Inner), which is also the value of Type.FullName.

public string FullName { get; }

Property value

string

GenericParameters

TypeElement.cs

Gets the names of the generic parameters of the type, including the ones of its containing types.

public IReadOnlyList<string> GenericParameters { get; }

Property value

IReadOnlyList<string>

Interfaces

TypeElement.cs

Gets the interfaces the type declares. Use TypeElement.Implements to include the interfaces of the base types.

public IReadOnlyList<TypeReference> Interfaces { get; }

IsAbstract

TypeElement.cs

Gets a value indicating whether the type is an abstract class. Interfaces and static classes are not abstract classes.

public bool IsAbstract { get; }

Property value

bool

Gets a value indicating whether the type is a class, including a record class.

public bool IsClass { get; }

Property value

bool

IsDelegate

TypeElement.cs

Gets a value indicating whether the type is a delegate.

public bool IsDelegate { get; }

Property value

bool

Gets a value indicating whether the type is an enum.

public bool IsEnum { get; }

Property value

bool

Gets a value indicating whether the type has generic parameters, including the ones of its containing types.

public bool IsGeneric { get; }

Property value

bool

IsImmutable

TypeElement.cs

Gets a value indicating whether the instances of the type cannot be modified: its instance fields are readonly or constant, and its instance properties have no setter, or an init setter. The types of the fields are not checked.

public bool IsImmutable { get; }

Property value

bool

IsInterface

TypeElement.cs

Gets a value indicating whether the type is an interface.

public bool IsInterface { get; }

Property value

bool

Gets a value indicating whether the type is nested in another type.

public bool IsNested { get; }

Property value

bool

Gets a value indicating whether the type is declared public. A public type nested in a non-public type is public.

public bool IsPublic { get; }

Property value

bool

Gets a value indicating whether the type is a record class or a record struct.

public bool IsRecord { get; }

Property value

bool

Gets a value indicating whether no type can inherit from the type: a sealed class, a struct, an enum or a delegate. Static classes are not sealed.

public bool IsSealed { get; }

Property value

bool

Gets a value indicating whether the type is a static class.

public bool IsStatic { get; }

Property value

bool

Gets a value indicating whether the type is a struct, including a record struct.

public bool IsStruct { get; }

Property value

bool

Gets the kind of the type.

public TypeElementKind Kind { get; }

Property value

TypeElementKind

Gets the first statement of the type when the PDB is available, or null.

public SourceLocation? Location { get; }

Property value

SourceLocation?

Gets all the members: constructors, methods, properties, fields and events.

public IReadOnlyList<MemberElement> Members { get; }

MetadataName

TypeElement.cs

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

public string MetadataName { get; }

Property value

string

Gets the methods, except the constructors, the accessors of the properties and events, and the methods generated by the compiler (lambdas, local functions).

public IReadOnlyList<MethodElement> Methods { get; }

Gets the name of the type, without the namespace, the containing type and the generic arity (Repository for Repository<T>).

public string Name { get; }

Property value

string

Gets the namespace of the type, or of its outermost containing type for a nested type.

public string Namespace { get; }

Property value

string

NestedTypes

TypeElement.cs

Gets the nested types, except the ones generated by the compiler.

public IReadOnlyList<TypeElement> NestedTypes { get; }

Properties

TypeElement.cs

Gets the properties and indexers.

public IReadOnlyList<PropertyElement> Properties { get; }

Methods

NameDescription
HasAttribute(Type)Determines whether the type has an attribute of the given type.
HasAttribute<T>()Determines whether the type has an attribute of type T.
Implements(string)Determines whether the type, one of its base types, or one of their interfaces implements the interface whose metadata name is fullName.
Implements(Type)Determines whether the type, one of its base types, or one of their interfaces implements interfaceType.
Implements<T>()Determines whether the type, one of its base types, or one of their interfaces implements T.
InheritsFrom(string)Determines whether the type inherits, directly or not, from the type whose metadata name is fullName.
InheritsFrom(Type)Determines whether the type inherits, directly or not, from baseType. The base types are resolved in the referenced assemblies.
InheritsFrom<T>()Determines whether the type inherits, directly or not, from T. The base types are resolved in the referenced assemblies.
Is(Type)Determines whether the type is type, or its generic type definition.
IsAssignableTo(string)Determines whether the type is the type whose metadata name is fullName, inherits from it, or implements it.
IsAssignableTo(Type)Determines whether the type is type, inherits from it, or implements it.
IsAssignableTo<T>()Determines whether the type is T, inherits from it, or implements 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#: MyApp.Repository<T>, MyApp.Outer.Inner.

HasAttribute overloads

HasAttribute(Type)

TypeElement.cs

Determines whether the type has an attribute of the given type.

public bool HasAttribute(Type attributeType)
Parameters
attributeType Type
The type of the attribute.
Returns

bool true when one of the attributes of the type is of this type.

HasAttribute<T>()

TypeElement.cs

Determines whether the type has an attribute of type T.

public bool HasAttribute<T>() where T : Attribute
Type parameters
T
The type of the attribute.
Returns

bool true when one of the attributes of the type is of this type.

Implements overloads

Implements(string)

TypeElement.cs

Determines whether the type, one of its base types, or one of their interfaces implements the interface whose metadata name is fullName.

public bool Implements(string fullName)
Parameters
fullName string
The full name of the interface as written in metadata (MyApp.IHandler`1).
Returns

bool true when the type implements the interface.

Implements(Type)

TypeElement.cs

Determines whether the type, one of its base types, or one of their interfaces implements interfaceType.

public bool Implements(Type interfaceType)
Parameters
interfaceType Type
The interface, or a generic type definition (typeof(IHandler<>)) to match all its instantiations.
Returns

bool true when the type implements the interface.

Implements<T>()

TypeElement.cs

Determines whether the type, one of its base types, or one of their interfaces implements T.

public bool Implements<T>()
Type parameters
T
The interface. For a generic interface, all its instantiations match.
Returns

bool true when the type implements the interface.

InheritsFrom overloads

InheritsFrom(string)

TypeElement.cs

Determines whether the type inherits, directly or not, from the type whose metadata name is fullName.

public bool InheritsFrom(string fullName)
Parameters
fullName string
The full name of the base type as written in metadata (MyApp.Repository`1).
Returns

bool true when one of the base types has this name.

InheritsFrom(Type)

TypeElement.cs

Determines whether the type inherits, directly or not, from baseType. The base types are resolved in the referenced assemblies.

public bool InheritsFrom(Type baseType)
Parameters
baseType Type
The base type, or a generic type definition (typeof(Repository<>)) to match all its instantiations.
Returns

bool true when one of the base types is baseType.

InheritsFrom<T>()

TypeElement.cs

Determines whether the type inherits, directly or not, from T. The base types are resolved in the referenced assemblies.

public bool InheritsFrom<T>()
Type parameters
T
The base type. For a generic type, all its instantiations match.
Returns

bool true when one of the base types is T.

Determines whether the type is type, or its generic type definition.

public bool Is(Type type)

Parameters

type Type
The type to compare with.

Returns

bool true when the full names match.

IsAssignableTo overloads

IsAssignableTo(string)

TypeElement.cs

Determines whether the type is the type whose metadata name is fullName, inherits from it, or implements it.

public bool IsAssignableTo(string fullName)
Parameters
fullName string
The full name of the type as written in metadata.
Returns

bool true when a value of this type can be assigned to a variable of this type.

IsAssignableTo(Type)

TypeElement.cs

Determines whether the type is type, inherits from it, or implements it.

public bool IsAssignableTo(Type type)
Parameters
type Type
The type, or a generic type definition.
Returns

bool true when a value of this type can be assigned to a variable of type.

IsAssignableTo<T>()

TypeElement.cs

Determines whether the type is T, inherits from it, or implements it.

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

bool true when a value of this type can be assigned to a variable of T.

IsInNamespace(string)

TypeElement.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 TypeElement.Namespace is namespace.

See also

IsInNamespaceOrChildren(string)

TypeElement.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 TypeElement.Namespace is namespace or starts with namespace followed by a dot.

See also

ToString()

TypeElement.cs

Returns the type as written in C#: MyApp.Repository<T>, MyApp.Outer.Inner.

public override string ToString()

Returns

string The type as written in C#.