Enables support for C# 9's record types and
init setters in Unity.
Unity 2021.2 technically supports C# 9, but some of its language features rely on runtime libraries that aren't available in .NET Standard 2.1. This package defines an internal class that these features require in order to function.
The included assembly originally came from this NuGet package (source).
Follow the instructions given here to install this package in your project via OpenUPM.
This package is delivered as a precompiled assembly
so that all assembly definitions reference it automatically.
There's no public API unless you count the enabled language features.
As a result,
you can get started
using standard records and
init setters immediately.
There are some minor caveats when using this package:
- If an assembly definition uses the "Override References" setting to reference precompiled assemblies explicitly,
you'll need to add a reference to
IsExternalInit.System.Runtime.CompilerServices. Otherwise, thatasmdefwon't be able to userecords orinit. - Unity doesn't currently support serializing or editing
records, so you'll need to implement that yourself. - A future release of Unity with built-in support for
records andinitmay break this package due to potential naming conflicts with theSystem.Runtime.CompilerServicesnamespace. When that happens, I'll add a#defineconstraint tied to it to minimize disruptions.
This package should work in any version of Unity that provides at least partial support for C# 9, starting with 2021.2.
The provided assembly is disabled in older versions of Unity (i.e. versions that don't define UNITY_2021_2_OR_NEWER).