IsExternalInit

Compiler polyfill that enables C# 9 init-only property accessors in Unity projects targeting .NET Standard 2.1. This is a zero-cost, marker-only class with no runtime behavior.

Definition

Namespace: System.Runtime.CompilerServices Assembly: Paragon.dll

[JetBrains.Annotations.UsedImplicitly]
internal static class IsExternalInit

Remarks

C# 9 introduced init-only setters, which allow properties to be set during object initialization but not afterward. The compiler requires the System.Runtime.CompilerServices.IsExternalInit type to exist in the assembly for this feature to work.

Unity's .NET Standard 2.1 profile does not include this type, so this empty static class acts as a polyfill. Its mere existence satisfies the compiler requirement — it contains no methods or fields.

How It Works

When the C# compiler encounters an init accessor:

public string Name { get; init; }

It generates IL that references System.Runtime.CompilerServices.IsExternalInit. If this type is missing, compilation fails with:

error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

This polyfill class provides the type, enabling init syntax throughout the Paragon codebase.

Why internal

The class is internal to prevent it from being visible to other assemblies, which might define their own polyfill. The [UsedImplicitly] attribute suppresses ReSharper/Rider warnings about the class appearing unused.

Quick Lookup

Goal
How

Use init properties

Just write { get; init; } — this polyfill makes it work

Prerequisite

None — simply having this file in the project is sufficient

Common Pitfalls

circle-info

No action required This class is a compile-time polyfill. You never need to reference, instantiate, or interact with it. If you see it in the codebase, leave it as-is.

circle-exclamation

Examples

Using init-only Properties

With this polyfill in the project, init accessors work as expected:

Records and init

init accessors also enable record types and with expressions:

See Also

Last updated