Compat - Totally makes compatibility layer for .NET platforms.
| Package | NuGet |
|---|---|
| Compat |
- TODO: Still under construction...
Totally makes compatibility layer for .NET platforms.
For examples:
// Undefined in net35:
if (string.IsNullOrWhitespace("ABC"))
{
}
// Use Compat and use StringEx instead:
if (StringEx.IsNullOrWhitespace("ABC"))
{
}// Undefined in most .NET Frameworks without using Compat.
// (Zip operator simple overload)
var zipped = left.Zip(right);// Undefined under net6.0 without using Compat.
// (WaitAsync method)
var zipped = this.CalculateAsync().WaitAsync(token);// Undefined TFM complex condition without using Compat.
// (ValueTask and ValueTask<T> types)
public async ValueTask<int> CalculateAsync()
{
// (Has ability of awaitable)
await this.RunOtherCalculationAsync();
}- .NET 7, 6, 5
- .NET Core 3.1, 3.0, 2.2, 2.1, 2.0
- .NET Standard 2.1, 2.0, 1.6, 1.3
- .NET Framework 4.8, 4.6.2, 4.6.1, 4.5.2, 4.5, 4.0, 3.5
Install Compat package.
The list is not completed minor status.
| Members | Status |
|---|---|
System.ValueTuple |
Added 4 type argument versions. |
System.Threading.Tasks.Task |
WaitAsync methods. |
System.Threading.Tasks.TaskEx |
Ports with AsyncBridge and Microsoft.Bcl.Async. Added some lack members. |
System.Threading.Tasks.ValueTask |
Supported async method builders (async-awaitable) |
| String interpolation features | FormattedString and DefaultInterpolatedStringHandler types. |
System.Linq operators |
Append, Prepend, TakeLast, SkipLast, Zip and ToHashSet methods. |
Lack some Task members in earlier third-party library:
System.Threading.Tasks.TaskEx.FromException()is not defined in third-party library.- Use
Task.Factory.FromException()instead. - Mostly useful
From{...}type method. So definedTask.Factory.FromResult()in near place. - Mostly useful
CompletedTaskproperty. So definedTask.Factory.CompletedTask()method in near place.
- Use
When you want to build .NET Framework project in Linux and other non-Windows environment, that package supports ability for referencing of .NET Framework assemblies:
<ItemGroup>
<PackageReference
Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3"
PrivateAssets="All" />
</ItemGroup>Completely hidden Compat assembly into your project
We suggest using ILRepack.FullAuto.
Backport PRs are welcome. The following is our backporting policy:
- Basically, target under the
Systemnamespace of the BCL library. - If a class, structure, or other type does not exist in the first place, define a new one.
- Use extended methods when porting instance methods.
- When porting instance properties or static members, define a type with
Exat the end and define members there.- This is to conform to existing conventions, such as
TaskExforTask.
- This is to conform to existing conventions, such as
- If you refer to a third-party library, there must be no alternative to this library or it must be well known.
- Example: AsyncBridge package, which was a community-based pre-distribution in TPL.
- Example: Microsoft.Bcl.Async package, which provides backward compatibility of
Taskwith .NET Framework 4.0.
- When referencing third-party libraries, do not generate unnecessary references.
- For example,
net6.0is nearly up-to-date, and references to libraries should not be included when usingnet6.0. To achieve this, define thePackageReferenceto be excluded byCondition.
- For example,
- Add the new TFM if it is to fill an incompatibility with a TFM that is not currently included.
- Do not include non-backporting any extensions.
- Write some kind of unit test. Of course, a comprehensive and exhaustive test code would be perfect.
Apache-v2.
- 0.3.0:
- Added
Unsafemethods (partially). - Adjusted ValueTask related package version dependency.
- Added
- 0.2.0:
- Added some LINQ operators.
- Added
Task.WaitAsyncmethods.
- 0.1.0:
- Added
ValueTask,ValueTupleand some minor members. - Adjust dependencies.
- Added
- 0.0.1:
- Initial public release.
