Open sandboxFocus

Interface INamedType

Represents a named type: class, struct, interface, enum, delegate, or record.

Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
public interface INamedType : IType, IEquatable<IType>, IGeneric, IMemberOrNamedType, INamespaceOrNamedType, INamedDeclaration, IDeclaration, IDisplayable, IDiagnosticLocation, ICompilationElement, IMeasurable, IEquatable<IDeclaration>, IEquatable<INamedType>
Remarks

Named types are the fundamental building blocks of C# programs. Unlike other types in the type system (such as arrays, pointers, or type parameters), named types have a fully qualified name, can contain members (methods, properties, fields, events, constructors), can implement interfaces, inherit from base types, and can have nested types.

To obtain an INamedType, you can:

For generic types, use MakeGenericInstance(IReadOnlyList<IType>) to create a constructed generic type from a generic definition.

Properties

Name Description
AllEvents

Gets the list of events defined in the current type or inherited from the base types.

AllFields

Gets the list of fields defined in the current type or inherited from the base types. Note that fields can be promoted to properties by aspects, so a source code field can be represented in the Properties collection instead of the Fields collection.

AllFieldsAndProperties

Gets the union of the AllFields and AllProperties collections.

AllImplementedInterfaces

Gets the list of all interfaces (recursive) that the current type implements.

AllIndexers

Gets the list of indexers defined in the current type or inherited from the base types.

AllMethods

Gets the list of methods defined in the current type or inherited from the base type.

AllProperties

Gets the list of properties defined in the current type or inherited from the base types. Note that fields can be promoted to properties by aspects, so a source code field can be represented in the Properties collection instead of the Fields collection.

AllTypes

Gets the list of nested types defined in the current type or inherited from the base types.

BaseType

Gets the type from which the current type derives.

Constructors

Gets the list of constructors, including the implicit default constructor if any, but not the static constructor.

ContainingNamespace

Gets the namespace of the current type.

Definition

Gets the type definition with unassigned type parameters. When the current INamedType is not a generic type instance, returns the current INamedType.

Events

Gets the list of events defined in the current type, but not those inherited from the base types.

ExtensionBlocks

Gets the list of extension blocks.

Fields

Gets the list of fields defined in the current type, but not those inherited from the base type. Note that fields can be promoted to properties by aspects, so a source code field can be represented in the Properties collection instead of the Fields collection.

FieldsAndProperties

Gets the union of the Fields and Properties collections.

Finalizer

Gets the finalizer of the type. For value types returns null.

HasDefaultConstructor
ImplementedInterfaces

Gets the list of interfaces that the current type implements.

Indexers

Gets the list of indexers defined in the current type.

IsReadOnly

Gets a value indicating whether the type is readonly.

IsRecord

Gets a value indicating whether type is a record. Also returns false when the type neither a class nor a record.

IsRef

Gets a value indicating whether the type is a ref struct.

Methods

Gets the list of methods defined in the current type, but not those inherited from the base type, and not constructors or the finalizer.

Namespace
NestedTypes

Gets the nested types of the current type.

PrimaryConstructor

Gets the primary constructor if it is defined, otherwise returns null.

Properties

Gets the list of properties defined in the current type, but not those inherited from the base types. Note that fields can be promoted to properties by aspects, so a source code field can be represented in the Properties collection instead of the Fields collection.

StaticConstructor

Gets the static constructor.

TypeDefinition
UnderlyingType

Gets the underlying type of an enum, the non-nullable type of a nullable reference type, or the current type.

Methods

Name Description
IsSubclassOf(INamedType)

Determines whether the type if subclass of the given class or interface.

MakeGenericInstance(IReadOnlyList<IType>)

Creates a constructed generic type from the current generic type definition with the specified type arguments.

StripNullabilityAnnotation()

Strips the nullability annotation from the current type, returning an unannotated version.

ToNullable()

Creates a nullable type from the current IType. If the current type is already nullable, returns the current type. If the type is a value type, returns a Nullable<T> of this type.

ToRef()

Gets a reference that can be used to identify the current declaration across different compilation versions.

TryFindImplementationForInterfaceMember(IMember, out IMember?)

Finds the the implementation of the given interface member that is valid for this type.

Extension Methods

See Also