-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from CptWesley/sourcegenerator
SourceGenerator Version
- Loading branch information
Showing
12 changed files
with
464 additions
and
208 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...Generator.PreNet5Tests/Backport.System.Threading.Lock.SourceGenerator.PreNet5Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net462;net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" /> | ||
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" /> | ||
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="System.Net.Http" /> | ||
<PackageReference Include="System.Text.RegularExpressions" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Backport.System.Threading.Lock\Backport.System.Threading.Lock.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Backport.System.Threading.Lock.SourceGenerator\Backport.System.Threading.Lock.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="../Backport.System.Threading.Lock.PreNet5Tests/*.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
39 changes: 39 additions & 0 deletions
39
...ng.Lock.SourceGenerator.Tests/Backport.System.Threading.Lock.SourceGenerator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="System.Net.Http" /> | ||
<PackageReference Include="System.Text.RegularExpressions" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Backport.System.Threading.Lock.SourceGenerator\Backport.System.Threading.Lock.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="../Backport.System.Threading.Lock.Tests/*.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
90 changes: 90 additions & 0 deletions
90
...stem.Threading.Lock.SourceGenerator/Backport.System.Threading.Lock.SourceGenerator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
<Authors>Mark Cilia Vincenti</Authors> | ||
<RepositoryUrl>https://github.com/MarkCiliaVincenti/Backport.System.Threading.Lock.git</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/MarkCiliaVincenti/Backport.System.Threading.Lock</PackageProjectUrl> | ||
<Copyright>MIT</Copyright> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<Version>2.0.7</Version> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<PackageReleaseNotes>Final .NET 9.0 release.</PackageReleaseNotes> | ||
<Description>A micro-library that backports/polyfills .NET 9.0+'s System.Threading.Lock to prior framework versions (from .NET Framework 3.5 up to .NET 8.0), providing as much backward compatibility as possible.</Description> | ||
<Copyright>© 2024 Mark Cilia Vincenti</Copyright> | ||
<PackageTags>System.Threading.Lock,lock,backport,polyfill,backward,compatible,compatibility,synchronization,synchronisation</PackageTags> | ||
<RepositoryType>git</RepositoryType> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<AssemblyVersion>2.0.7.0</AssemblyVersion> | ||
<FileVersion>2.0.7.0</FileVersion> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<IsPackable>true</IsPackable> | ||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> | ||
<EnableNETAnalyzers>True</EnableNETAnalyzers> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<SignAssembly>True</SignAssembly> | ||
<AssemblyOriginatorKeyFile>Backport.System.Threading.Lock.SourceGenerator.snk</AssemblyOriginatorKeyFile> | ||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild> | ||
<ImplicitUsings>false</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(DefineConstants.Contains(AOT_COMPATIBLE))"> | ||
<IsAotCompatible>true</IsAotCompatible> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(DefineConstants.Contains(TRIMMING_COMPATIBLE))"> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<TrimmerDefaultAction>link</TrimmerDefaultAction> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<DevelopmentDependency>true</DevelopmentDependency> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="DependencyPackaging"> | ||
<None Include="$(OutputPath)/netstandard2.0/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="Properties\PublishProfiles\**" /> | ||
<EmbeddedResource Remove="Properties\PublishProfiles\**" /> | ||
<None Remove="Properties\PublishProfiles\**" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
<None Include="..\logo.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\CONTRIBUTORS.md"> | ||
<Pack>False</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="../Backport.System.Threading.Lock/Lock.cs" /> | ||
<EmbeddedResource Include="../Backport.System.Threading.Lock/LockFactory.cs" /> | ||
<EmbeddedResource Include="../Backport.System.Threading.Lock/PreNet5Lock.cs" /> | ||
<EmbeddedResource Include="../Backport.System.Threading.Lock/Properties/AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="All" /> | ||
</ItemGroup> | ||
</Project> |
Binary file added
BIN
+596 Bytes
....System.Threading.Lock.SourceGenerator/Backport.System.Threading.Lock.SourceGenerator.snk
Binary file not shown.
36 changes: 36 additions & 0 deletions
36
Backport.System.Threading.Lock.SourceGenerator/Generator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.CodeAnalysis; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Backport.System.Threading.Lock.SourceGenerator; | ||
|
||
[Generator] | ||
internal sealed class Generator : IIncrementalGenerator | ||
{ | ||
private static readonly Assembly Assembly = typeof(Generator).Assembly; | ||
|
||
public void Initialize(IncrementalGeneratorInitializationContext context) | ||
=> context.RegisterPostInitializationOutput(Generate); | ||
|
||
private static void Generate(IncrementalGeneratorPostInitializationContext context) | ||
{ | ||
foreach (var resource in Assembly.GetManifestResourceNames()) | ||
{ | ||
Generate(context, resource); | ||
} | ||
} | ||
|
||
private static void Generate(IncrementalGeneratorPostInitializationContext context, string resourceName) | ||
{ | ||
using var stream = Assembly.GetManifestResourceStream(resourceName); | ||
using var streamReader = new StreamReader(stream); | ||
var text = streamReader.ReadToEnd(); | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendLine("#define SOURCE_GENERATOR"); | ||
sb.AppendLine(text); | ||
|
||
context.AddSource(resourceName, sb.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.