This project contains unit tests that verify the availability of C# features that were added in C# 8.0 or higher using polyfills provided by PolySharp when targeting .NET Framework 4.5.1 through 4.8. Wherever possible, the tests use samples from Microsoft's own online documentation for the individual features.
NOTE: Tests for .NET Framework 4.5 are not provided as the .NET Framework 4.5 SDK is well past its end of life and Microsoft no longer makes it available for download from .NET SDK Downloads for Visual Studio.
As the SDK can no longer be acquired, forks of this repository would not be able to run these tests if they did not already have the SDK installed.
This document lists all C# features that were added from C# 8 forward, and notes where features are either not supported or require additional setup or configuration.
PolySharp is sponsored by Sergio Pedri, and be found on github here. The NuGet package is available at NuGet.org here.
- Add a reference to PolySharp from NuGet Package Manager.
- Manually add the analyzer to the project. In Solution Explorer, expand References, and right-click Analyzers. Select Add Analyzer. Browse to
packages\PolySharp.1.10.0\analyzers\dotnet\cs\and selectPolySharp.SourceGenerators.dll. Then clean and rebuild your solution.
If your project uses a packages.config file, consider migrating it to use the newer PackageReference element in the .csproj file. Source code generation is more reliable when PackageReference elements are used as opposed to a packages.config file.
Each of the pages below provides a feature compatibility matrix that describes the availability of each feature in each version of the .NET Framework tested.
In each section below, if a bullet point is a hyperlink, the feature has been tested via unit test. Unless otherwise specified, the presence of a hyperlink indicates that the tests pass, and the feature is available via polyfill and works as documented in the linked Microsoft online documentation.
- Readonly members
- Default interface methods
- Not supported; requires support only available in later runtime versions.
- Pattern matching enhancements:
- Using declarations
- Static local functions
- Nullable reference types
- Asynchronous streams
- Not supported prior to .NET Framework 4.6.1.
- Requires a reference to Microsoft.Bcl.AsyncInterfaces.
- Indices and ranges:
- Index from End operator
- Range operator
- Not supported on arrays unless converted to a Span<T> or ReadOnlySpan<T>.
- Requires a reference to System.Memory.dll.
- Null-coalescing assignment
- Unmanaged constructed types
- Stackalloc in nested expressions
- Enhancement of interpolated verbatim strings
- Record types
- Init only setters
- Top-level statements
- Not verifiable via unit test. However, the
TopLevelStatementsTestproject is a console application that verifies that this feature works as documented.
- Not verifiable via unit test. However, the
- Pattern matching enhancements
- Performance and interop
- Native sized integers
- Function pointers
- Suppress emitting localsinit flag
- Fit and finish features
- Support for code generators
- Warning wave 5
- Record structs
- Improvements of structure types
- Interpolated string handlers
- Global using directives
- File-scoped namespace declaration
- Not testable via unit test. However, all types in the CSharp10 folder use file-scoped namespace declarations, verifying that this functionality compiles and works as intended.
- Extended property patterns
- Improvements on lambda expressions
- Allow const interpolated strings
- Record types can seal ToString()
- Improved definite assignment
- Allow both assignment and declaration in the same deconstruction
- Allow AsyncMethodBuilder attribute on methods
- CallerArgumentExpression attribute
- Enhanced #line pragma
- Warning wave 6
- Raw string literals
- Generic math support
- Generic attributes
- UTF-8 string literals
- Newlines in string interpolation expressions
- List patterns
- File-local types
- Required members
- Auto-default structs
- Pattern match Span<char> on a constant string
- Extended nameof scope
- Numeric IntPtr
- ref fields and scoped ref
- Improved method group conversion to delegate
- Warning wave 7