Open sandboxFocus

Method GetImmutabilityKind

GetImmutabilityKind(IType)

Returns the ImmutabilityKind for a given type.

Declaration
public static ImmutabilityKind GetImmutabilityKind(this IType type)
Parameters
Type Name Description
IType type

The type to evaluate.

Returns
Type Description
ImmutabilityKind

The ImmutabilityKind of the type, determined by the following rules in order:

Remarks

The rule for a union rests on the definition that Shallow gives, which is about instance fields and automatic property setters, and not on the type being declared readonly. A union declaration satisfies that definition whether or not it carries the modifier, because its only instance field is the read-only backing field of the synthesized get-only Value property, and the language reports an error for an instance field, an automatic property or a field-like event declared in a union.

The rule applies to the declaration form only. A class or a struct that carries the System.Runtime.CompilerServices.UnionAttribute attribute is also a union, its state is unconstrained, and it is classified by the rules that apply to any other class or struct. A union read from a referenced assembly is reported as the attribute form, because the compiled form of a union does not record whether the source used the union keyword, so a union of another project is classified by those rules as well.