Skip to content

Commit

Permalink
Reverted Microsoft.CodeAnalysis back to 4.1.0 because JetBrains Rider…
Browse files Browse the repository at this point in the history
… does not support 4.2.0 yet.

Made the `MetadataReferencesProvider` backwards compatible due to dotnet/roslyn#58059
  • Loading branch information
PawelGerr committed May 17, 2022
1 parent d472882 commit 57a7fdf
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
<VersionPrefix>4.3.0</VersionPrefix>
<VersionPrefix>4.3.1</VersionPrefix>
<Authors>Pawel Gerr</Authors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageProjectUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</PackageProjectUrl>
Expand Down
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
[![Thinktecture.Runtime.Extensions.Newtonsoft.Json](https://img.shields.io/nuget/vpre/Thinktecture.Runtime.Extensions.Newtonsoft.Json.svg?maxAge=60&label=Thinktecture.Runtime.Extensions.Newtonsoft.Json)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.Newtonsoft.Json/)
[![Thinktecture.Runtime.Extensions.MessagePack](https://img.shields.io/nuget/vpre/Thinktecture.Runtime.Extensions.MessagePack.svg?maxAge=60&label=Thinktecture.Runtime.Extensions.MessagePack)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.MessagePack.Json/)
[![Thinktecture.Runtime.Extensions.EntityFrameworkCore](https://img.shields.io/nuget/vpre/Thinktecture.Runtime.Extensions.EntityFrameworkCore.svg?maxAge=60&label=Thinktecture.Runtime.Extensions.EntityFrameworkCore)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.EntityFrameworkCore/)
[![Thinktecture.Runtime.Extensions.AspNetCore](https://img.shields.io/nuget/vpre/Thinktecture.Runtime.Extensions.AspNetCore.svg?maxAge=60&label=Thinktecture.Runtime.Extensions.AspNetCore)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.AspNetCore/)
[![Thinktecture.Runtime.Extensions.AspNetCore](https://img.shields.io/nuget/vpre/Thinktecture.Runtime.Extensions.AspNetCore.svg?maxAge=60&label=Thinktecture.Runtime.Extensions.AspNetCore)](https://www.nuget.org/packages/Thinktecture.Runtime.Extensions.AspNetCore/)

This library provides some interfaces, classes, [Roslyn Source Generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview), Roslyn Analyzers and Roslyn CodeFixes for implementation of **Smart Enums** and **Value Objects**.

See [wiki](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki) for more documentation.

# Required SDK/Compiler Version
* Compiler version: 4.2.0
* Compiler version: 4.1.0

Verify the version by placing `#error version` into any of your cs-files and build the project/solution.
The build output should display the compiler version:
The build output should display the compiler version:
```
MyFile.cs(15, 8): [CS1029] #error: 'version'
MyFile.cs(15, 8): [CS8304] Compiler version: '4.2.0-4.22220.2 (1e40aa11)'. Language version: 10.0.
MyFile.cs(15, 8): [CS8304] Compiler version: '4.1.0-5.22165.10 (e555772d)'. Language version: 10.0.
```

Update your IDE and SDK to newest version.
Works/tested with:
* SDK: 6.0.300
* Visual Studio: 17.2.0
* JetBrains Rider: 2022.1.1
* SDK: 6.0.202
* Visual Studio: 17.1.5
* JetBrains Rider: 2022.1

> Please note: For developers having both, JetBrains Rider and Visual Studio, please update Visual Studio as well, because Rider is using the SDK of Visual Studio by default.
Expand All @@ -39,21 +39,21 @@ Install: `Install-Package Thinktecture.Runtime.Extensions`
Documentation: [Smart Enums](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums)

Features:
* Roslyn Analyzers and CodeFixes help the developers to implement the Smart Enums correctly
* Allows iteration over all items
* Allows custom properties and methods
* Provides appropriate constructor based on the specified properties/fields
* Provides means for lookup, cast and type conversion from key-type to Smart Enum and vice versa
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
* Choice between always-valid `IEnum<T>` and maybe-valid `IValidatableEnum<T>`
* Allows extensions of existing Smart Enums
* Allows custom validation of constructor arguments
* Allows changing the propery name `Key`, which holds the underlying value - thanks to [Roslyn Source Generator](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview)
* Allows custom key comparer
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
* ASP.NET Core support (model binding and model validation)
* Entity Framework Core support (`ValueConverter`)
* MessagePack support (`IMessagePackFormatter`)
* Roslyn Analyzers and CodeFixes help the developers to implement the Smart Enums correctly
* Allows iteration over all items
* Allows custom properties and methods
* Provides appropriate constructor based on the specified properties/fields
* Provides means for lookup, cast and type conversion from key-type to Smart Enum and vice versa
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
* Choice between always-valid `IEnum<T>` and maybe-valid `IValidatableEnum<T>`
* Allows extensions of existing Smart Enums
* Allows custom validation of constructor arguments
* Allows changing the propery name `Key`, which holds the underlying value - thanks to [Roslyn Source Generator](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview)
* Allows custom key comparer
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
* ASP.NET Core support (model binding and model validation)
* Entity Framework Core support (`ValueConverter`)
* MessagePack support (`IMessagePackFormatter`)

Definition of a new Smart Enum without any custom properties and methods. All other features mentioned above are generated by the [Roslyn Source Generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview) in the background.

Expand Down Expand Up @@ -102,20 +102,20 @@ Install: `Install-Package Thinktecture.Runtime.Extensions`
Documentation: [Immutable Value Objects](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Immutable-Value-Objects)

Features:
* Roslyn Analyzers and CodeFixes help the developers to implement the Value Objects correctly
* Allows custom properties and methods
* Provides appropriate factory methods for creation of new value objects based on the specified properties/fields
* Allows custom validation of constructor and factory method arguments
* Additional features for simple Value Objects (1 "key"-property/field) and complex Value Objects (2 properties/fields or more)
* Simple Value Objects: allows cast and type conversion from key-type to Value Object and vice versa
* Simple Value Objects: provides an implementation of `IComparable<T>` if the key-property/field is an `IComparable<T>` or has an `IComparer<T>`
* Simple Value Objects: provides an implementation of `IFormattable` if the key-property/field is an `IFormattable`
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
* Allows custom equlity comparison
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
* ASP.NET Core support (model binding and model validation)
* Entity Framework Core support (`ValueConverter`)
* MessagePack support (`IMessagePackFormatter`)
* Roslyn Analyzers and CodeFixes help the developers to implement the Value Objects correctly
* Allows custom properties and methods
* Provides appropriate factory methods for creation of new value objects based on the specified properties/fields
* Allows custom validation of constructor and factory method arguments
* Additional features for simple Value Objects (1 "key"-property/field) and complex Value Objects (2 properties/fields or more)
* Simple Value Objects: allows cast and type conversion from key-type to Value Object and vice versa
* Simple Value Objects: provides an implementation of `IComparable<T>` if the key-property/field is an `IComparable<T>` or has an `IComparer<T>`
* Simple Value Objects: provides an implementation of `IFormattable` if the key-property/field is an `IFormattable`
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
* Allows custom equlity comparison
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
* ASP.NET Core support (model binding and model validation)
* Entity Framework Core support (`ValueConverter`)
* MessagePack support (`IMessagePackFormatter`)

Definition of a value object with 1 custom property `Value`. All other features mentioned above are generated by the [Roslyn Source Generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview) in the background.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Collect()
.SelectMany(static (states, _) => states.Distinct());

var generators = context.MetadataReferencesProvider
var generators = context.GetMetadataReferencesProvider()
.SelectMany(static (reference, _) => TryGetCodeGeneratorFactory(reference, out var factory)
? ImmutableArray.Create(factory)
: ImmutableArray<ICodeGeneratorFactory<EnumSourceGeneratorState>>.Empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Collect()
.SelectMany(static (states, _) => states.Distinct());

var generators = context.MetadataReferencesProvider
var generators = context.GetMetadataReferencesProvider()
.SelectMany(static (reference, _) => TryGetCodeGeneratorFactory(reference, out var factory)
? ImmutableArray.Create(factory)
: ImmutableArray<ICodeGeneratorFactory<ValueObjectSourceGeneratorState>>.Empty)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

namespace Thinktecture;

public static class IncrementalGeneratorInitializationContextExtensions
{
public static IncrementalValuesProvider<MetadataReference> GetMetadataReferencesProvider(this IncrementalGeneratorInitializationContext context)
{
var metadataProviderProperty = context.GetType().GetProperty(nameof(context.MetadataReferencesProvider))
?? throw new Exception($"The property '{nameof(context.MetadataReferencesProvider)}' not found");

var metadataProvider = metadataProviderProperty.GetValue(context);

if (metadataProvider is IncrementalValuesProvider<MetadataReference> metadataValuesProvider)
return metadataValuesProvider;

if (metadataProvider is IncrementalValueProvider<MetadataReference> metadataValueProvider)
return metadataValueProvider.SelectMany(static (reference, _) => ImmutableArray.Create(reference));

throw new Exception($"The '{nameof(context.MetadataReferencesProvider)}' is neither an 'IncrementalValuesProvider<{nameof(MetadataReference)}>' nor an 'IncrementalValueProvider<{nameof(MetadataReference)}>.'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<IncludeSymbols>false</IncludeSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" PrivateAssets="all" />

<Compile Include="..\..\shared\IsExternalInit.cs">
<Link>IsExternalInit.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" />
</ItemGroup>

</Project>

0 comments on commit 57a7fdf

Please sign in to comment.