Open sandboxFocus

Property IsClosed

IsClosed

Gets or sets a value indicating whether the type is declared with the closed modifier of C# 15.

Declaration
bool IsClosed { get; set; }
Property Value
Type Description
bool
Remarks

The language allows the closed modifier on a class only, and forbids it on a sealed class and on a static class. The setter throws an InvalidOperationException when one of these restrictions is not met.

A closed class is implicitly abstract, so IsAbstract reports true as soon as this property is set, and the generated declaration carries the closed keyword instead of the abstract keyword. Setting IsAbstract to false on a closed type throws an InvalidOperationException.

Metalama runs inside a host, which is the compiler during a build and the integrated development environment at design time, and the host supplies the version of Roslyn that Metalama uses. Setting this property to true throws an InvalidOperationException when that version does not offer C# 15, because the closed keyword cannot be generated then. A host that supplies such a version does not support the language feature at all, so it cannot compile a closed class either.