Adds C# 9/10's record/record struct support for .NET Framework 2, 3, and 3.5.
As of January 10th 2023, this library will no longer be maintained and is considered obsolete in favor of a better alternative:
-
Add InlineIL.Fody as a dependency, setup of Fody is required.
-
Download this file; a modified version of the .NET Framework 3.5 binary.
- You can alternatively generate your own using this snippet.
-
Reference this binary in your
.csproj
, orDirectory.Build.targets
:
<ItemGroup Condition="'$(TargetFramework)' == 'net35'">
<Reference Include="mscorlib" Aliases="global, ms" Private="false" HintPath="$(SharedPath)Emik.Morsels/References/mscorlib.dll" />
</ItemGroup>
Refer to the prerequisite, then compile.
For more information on how or why this works, click here.
This library intentionally leaves out System.Runtime.CompilerServices.IsExternalInit
to be able to be better integrated with other excellent polyfilling libraries such as Theraot.Core
. Either use a package like Manual Roemer's IsExternalInit
, or define your own within the project:
using System.ComponentModel;
namespace System.Runtime.CompilerServices;
/// <summary>Reserved to be used by the compiler for tracking metadata. This class should not be used by developers in source code.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IsExternalInit
{
}
Record types, introduced in C# 9 and 10 are a fantastic feature that allows for easily creating data types with lots of overriden methods that lift a lot of heavy boilerplate out of classes. The feature was originally targetted for .NET 5, but can be used in previous frameworks by polyfilling System.Runtime.CompilerServices.IsExternalInit
.
However, prior to .NET Framework 4, the System.Type.op_Equality
and System.Type.op_Inequality
methods didn't exist. Roslyn still expects them to exist, and will therefore throw an error that this method is missing.
This library adds record and record struct functionality for old .NET Frameworks by create a wrapper class Type
that inherits the original, and polyfilling the required op_Equality
and op_Inequality
static methods by calling System.Type.Equals(Type)
which Roslyn scans for.
As with most GitHub repositories, you can contribute by:
- Creating an issue to either address bugs, feature suggestions, or other changes.
- Creating/reviewing pull requests is also welcome.