feO2x / Light.GuardClauses

A lightweight .NET library for expressive Guard Clauses.
MIT License
85 stars 8 forks source link

Provide source code NuGet package #54

Closed feO2x closed 5 years ago

feO2x commented 6 years ago

I think there might be need for a source-code-only NuGet package of Light.GuardClauses. There should be only a single file called Light.GuardClauses.cs and the whole public API should be made internal.

I think it's reasonable to automate the creation of this file using Roslyn. All files of Light.GuardClauses project could be parsed and merged into one file, and adjusting the syntax tree so that public becomes internal. The only thing that might get hard is the using statements (that sometimes contain precompile symbols to support all target platforms). Maybe the easiest thing is to hard-code the list of usings at the beginning of the file.

feO2x commented 6 years ago

This issue is actually harder to solve than expected. The problem is the use of #if precompiler symbols. Light.GuardClauses is compiled against the frameworks netstandard2.0;netstandard1.0;net45;net40;net35;net35-cf;sl5 and uses the corresponding constants to conditionally compile code for the different frameworks. This is bad if the target project which wants to include the Light.GuardClauses source code is not one of the frameworks mentioned above. In this case, the corresponding constants are not defined (e.g. if you use net47, then the NET45 constant is not defined). This leads to the wrong code being being compiled when the target project is build.

I think the easiest way to solve this problem is to make a .NET Standard 2.0 Source Code NuGet package.

feO2x commented 5 years ago

Implemented in 5a706cc8c740c70cc2027eae2ab22deb87958960.

I actually won't provide a NuGet package for this but check the latest version in as a single source code file. This way, developers can grab the source code by simply copy & pasting it in a file. Furthermore, there is now the Light.GuardClauses.SourceCodeTransformation project that developers can use to customize the Light.GuardClauses source code file (adjusting target namespace, make types internal, remove JetBrains annotations, and so on).