Skip to content

Enable support for C# 9's record types and the init keyword in Unity.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

CorundumGames/IsExternalInit

Repository files navigation

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

About

Enable support for C# 9's record types and the init keyword in Unity.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published