IsClosed
Gets a value indicating whether the type is declared with the closed modifier. Also returns false
when the type is not a class.
Declaration
bool IsClosed { get; }Property Value
| Type | Description |
|---|---|
| bool |
Remarks
A closed type is implicitly abstract, so IsAbstract is true and
IsSealed is false for it.
When the type is closed and is declared in the current compilation, the set returned by GetDerivedTypes(INamedType, DerivedTypesOptions) with DirectOnly is the complete set of the direct subtypes of the type, because the language requires every subtype of a closed type to be declared in the same module. That guarantee does not extend to a closed type declared in a referenced assembly, and it does not hold when the compilation model is built on a subset of the syntax trees of the project, which is the case at design time.
For a type introduced by an aspect, this property returns the value that the aspect set on
IsClosed. For a type declared in source, it returns
false when the Metalama engine that runs the aspect cannot read the closed modifier, in which case
no such type is reported as closed. That is the case for the engine built for a Roslyn version that
predates C# 15, and, in the current preview, for the engine built for the latest Roslyn version, because
the Roslyn member that reports the modifier is still experimental there.