Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 2.89 KB

README.md

File metadata and controls

47 lines (35 loc) · 2.89 KB

IsExternalInit

GitHub Workflow Status (branch) openupm

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).

Installation

Follow the instructions given here to install this package in your project via OpenUPM.

Usage

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, that asmdef won't be able to use records or init.
  • 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 and init may break this package due to potential naming conflicts with the System.Runtime.CompilerServices namespace. When that happens, I'll add a #define constraint tied to it to minimize disruptions.

Compatibility

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).