All Projects → manuelroemer → IsExternalInit

manuelroemer / IsExternalInit

Licence: MIT license
A source code only package which allows you to use C# 9's init and record features in older target frameworks like .NET Standard 2.0 or the "old" .NET Framework by providing a polyfill for the IsExternalInit class.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to IsExternalInit

Nullable
A source code only package which allows you to use .NET's nullable attributes in older target frameworks like .NET Standard 2.0 or the "old" .NET Framework.
Stars: ✭ 106 (+41.33%)
Mutual labels:  polyfill, source
smart-custom-element
Smart a lightweight web component library that provides capabilities for web components, such as data binding, using es6 native class inheritance. This library is focused for providing the developer the ability to write robust and native web components without the need of dependencies and an overhead of a framework.
Stars: ✭ 17 (-77.33%)
Mutual labels:  polyfill
barcode-detector
Spec compliant polyfill of the Barcode Detection API 🤳
Stars: ✭ 31 (-58.67%)
Mutual labels:  polyfill
GitHubSpanishRankingGenerator
Scripts to build the GitHub Spanish rankings (users most active in each province sorted by public contributions) 🇪🇸
Stars: ✭ 19 (-74.67%)
Mutual labels:  source
Blog
h2O's Blog
Stars: ✭ 18 (-76%)
Mutual labels:  record
LegionTD-Reborn
A custom game mode inspired by Legion TD for DotA 2
Stars: ✭ 34 (-54.67%)
Mutual labels:  source
go-init
A minimal init system for containers with pre/post hooks
Stars: ✭ 36 (-52%)
Mutual labels:  init
polyfill-php74
This component provides functions unavailable in releases prior to PHP 7.4.
Stars: ✭ 26 (-65.33%)
Mutual labels:  polyfill
XcodeCommentWrapper
Xcode extension for wrapping comments
Stars: ✭ 29 (-61.33%)
Mutual labels:  source
focus-options-polyfill
JavaScript polyfill for the WHATWG spec of focusOptions, that enables a set of options to be passed to the focus method
Stars: ✭ 46 (-38.67%)
Mutual labels:  polyfill
natick
natickOS - A minimal, lightweight, research Linux Distribution
Stars: ✭ 33 (-56%)
Mutual labels:  init
Mat-O-Wahl
🇩🇪 Mat-O-Wahl - Ein einfach zu bedienender, freier Open Source Wahl-O-Mat Klon fuer jedermann ### 🇬🇧 🇺🇸 A simple to handle, free "Voting Advice Application" / "Electoral Compass" alternative
Stars: ✭ 27 (-64%)
Mutual labels:  source
InitWare
The InitWare Suite of Middleware allows you to manage services and system resources as logical entities called units. Its main component is a service management ("init") system.
Stars: ✭ 164 (+118.67%)
Mutual labels:  init
NetMauMau
Server for the popular card game Mau Mau (similar to UNO®)
Stars: ✭ 16 (-78.67%)
Mutual labels:  source
Timeline
AS2 & AS3 CPPS Emulator, written in Python. (Club Penguin Private Server Emulator)
Stars: ✭ 49 (-34.67%)
Mutual labels:  source
Avalonia.PropertyGenerator
Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
Stars: ✭ 20 (-73.33%)
Mutual labels:  source
scoper
A polyfill for scoped HTML styles elements
Stars: ✭ 79 (+5.33%)
Mutual labels:  polyfill
canvas-record
A one trick pony package to record and download a video from a canvas animation.
Stars: ✭ 64 (-14.67%)
Mutual labels:  record
locerr
❌ locerr (locational error): Library for nice-looking errors in source code
Stars: ✭ 16 (-78.67%)
Mutual labels:  source
RecordWaveView
a beatiful wave animation for recording ,support android Mp3 record
Stars: ✭ 62 (-17.33%)
Mutual labels:  record

IsExternalInit Nuget

Use C# 9's init and record features in older target frameworks.

🏃 Quickstart   |   📦 NuGet


You may also want to check out my Nullable project which provides support for .NET's nullable reference type attributes for older target frameworks.


C# 9 added support for the init and record keywords. When using C# 9 with target frameworks <= .NET 5.0, using these new features is not possible because the compiler is missing the IsExternalInit class, hence making the features unavailable for any target framework prior to .NET 5.

Luckily, this problem can be solved by re-declaring the IsExternalInit class as an internal class in your own project. The compiler will use this custom class definition and thus allow you to use both the init keywords and records in any project.

This repository hosts the code for the "IsExternalInit" NuGet Package which, when referenced, automatically adds the IsExternalInit class to the referenced project(s).

The code for the IsExternalInit class is added at compile time and gets built into the referencing project. This means that the resulting project does not have an explicit dependency on the IsExternalInit package, because the code is not distributed as a standard library.

Compatibility

IsExternalInit is currently compatible with the following target frameworks:

  • .NET Standard >= 1.0
  • .NET Framework >= 2.0

Quickstart

⚠️ Important:
You must use a C# version >= 9.0 with the IsExternalInit package - otherwise, your project won't compile.

The steps below assume that you are using the new SDK .csproj style. Please find installation guides and notes for other project types (for example packages.config) here.

  1. Reference the package
    Add the package to your project, for example via:

    Install-Package IsExternalInit
    
    --or--
    
    dotnet add package IsExternalInit
  2. Ensure that the package has been added as a development dependency
    Open your .csproj file and ensure that the new package reference looks similar to this:

    <PackageReference Include="IsExternalInit" Version="<YOUR_VERSION>" PrivateAssets="all" />
    
    <!-- NuGet, by default, uses this style. This is also acceptable. -->
    <PackageReference Include="IsExternalInit" Version="<YOUR_VERSION>">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

    This is especially important for libraries that are published to NuGet, because without this, the library will have an explicit dependency on the IsExternalInit package.

  3. Build the project
    Ensure that the project compiles. If a build error occurs, you will most likely have to update the C# language version.

Afterwards, you can immediately start using the attributes.

Compiler Constants

The included C# file makes use of some compiler constants that can be used to enable or disable certain features.

ISEXTERNALINIT_DISABLE

If the ISEXTERNALINIT_DISABLE constant is defined, the IsExternalInit class is excluded from the build. This can be used to conditionally exclude code of this package from the build if it is not required.

In most cases, this should not be required, because the package automatically excludes the code from target frameworks that already support the IsExternalInit class.

ISEXTERNALINIT_INCLUDE_IN_CODE_COVERAGE

Because the IsExternalInit class is added as source code, it could appear in code coverage reports. By default, this is disabled via the ExcludeFromCodeCoverage and DebuggerNonUserCode attributes.

By defining the ISEXTERNALINIT_INCLUDE_IN_CODE_COVERAGE constant, the ExcludeFromCodeCoverage and DebuggerNonUserCode attributes are not applied and the IsExternalInit class may therefore appear in code coverage reports.

Building

Because the package consists of source files, building works differently than a normal .NET project. In essence, no build has to be made at all. Instead, the *.cs files are packaged into a NuGet package via a .nuspec file.

The solution contains a _build project which automatically performs these tasks though. You can then find the resulting NuGet package file in the artifacts folder.

Contributing

I don't expect this package to require many changes, but if something is not working for you or if you think that the source file should change, feel free to create an issue or Pull Request. I will be happy to discuss and potentially integrate your ideas!

License

See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].