Skip to content

Commit 57a7fdf

Browse files
committed
Reverted Microsoft.CodeAnalysis back to 4.1.0 because JetBrains Rider does not support 4.2.0 yet.
Made the `MetadataReferencesProvider` backwards compatible due to dotnet/roslyn#58059
1 parent d472882 commit 57a7fdf

File tree

8 files changed

+65
-42
lines changed

8 files changed

+65
-42
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
5-
<VersionPrefix>4.3.0</VersionPrefix>
5+
<VersionPrefix>4.3.1</VersionPrefix>
66
<Authors>Pawel Gerr</Authors>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageProjectUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</PackageProjectUrl>

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
[![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/)
88
[![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/)
99
[![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/)
10-
[![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/)
10+
[![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/)
1111

1212
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**.
1313

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

1616
# Required SDK/Compiler Version
17-
* Compiler version: 4.2.0
17+
* Compiler version: 4.1.0
1818

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

2626
Update your IDE and SDK to newest version.
2727
Works/tested with:
28-
* SDK: 6.0.300
29-
* Visual Studio: 17.2.0
30-
* JetBrains Rider: 2022.1.1
28+
* SDK: 6.0.202
29+
* Visual Studio: 17.1.5
30+
* JetBrains Rider: 2022.1
3131

3232
> 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.
3333
@@ -39,21 +39,21 @@ Install: `Install-Package Thinktecture.Runtime.Extensions`
3939
Documentation: [Smart Enums](https://github.com/PawelGerr/Thinktecture.Runtime.Extensions/wiki/Smart-Enums)
4040

4141
Features:
42-
* Roslyn Analyzers and CodeFixes help the developers to implement the Smart Enums correctly
43-
* Allows iteration over all items
44-
* Allows custom properties and methods
45-
* Provides appropriate constructor based on the specified properties/fields
46-
* Provides means for lookup, cast and type conversion from key-type to Smart Enum and vice versa
47-
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
48-
* Choice between always-valid `IEnum<T>` and maybe-valid `IValidatableEnum<T>`
49-
* Allows extensions of existing Smart Enums
50-
* Allows custom validation of constructor arguments
51-
* 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)
52-
* Allows custom key comparer
53-
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
54-
* ASP.NET Core support (model binding and model validation)
55-
* Entity Framework Core support (`ValueConverter`)
56-
* MessagePack support (`IMessagePackFormatter`)
42+
* Roslyn Analyzers and CodeFixes help the developers to implement the Smart Enums correctly
43+
* Allows iteration over all items
44+
* Allows custom properties and methods
45+
* Provides appropriate constructor based on the specified properties/fields
46+
* Provides means for lookup, cast and type conversion from key-type to Smart Enum and vice versa
47+
* Provides proper implementation of `Equals`, `GetHashCode`, `ToString` and equality comparison via `==` and `!=`
48+
* Choice between always-valid `IEnum<T>` and maybe-valid `IValidatableEnum<T>`
49+
* Allows extensions of existing Smart Enums
50+
* Allows custom validation of constructor arguments
51+
* 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)
52+
* Allows custom key comparer
53+
* JSON support (`System.Text.Json` and `Newtonsoft.Json`)
54+
* ASP.NET Core support (model binding and model validation)
55+
* Entity Framework Core support (`ValueConverter`)
56+
* MessagePack support (`IMessagePackFormatter`)
5757

5858
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.
5959

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

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

120120
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.
121121

samples/TT.EFCore.Benchmarking/TT.EFCore.Benchmarking.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
10-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
10+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
1111
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
1212
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1313
</ItemGroup>

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/SmartEnumSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2323
.Collect()
2424
.SelectMany(static (states, _) => states.Distinct());
2525

26-
var generators = context.MetadataReferencesProvider
26+
var generators = context.GetMetadataReferencesProvider()
2727
.SelectMany(static (reference, _) => TryGetCodeGeneratorFactory(reference, out var factory)
2828
? ImmutableArray.Create(factory)
2929
: ImmutableArray<ICodeGeneratorFactory<EnumSourceGeneratorState>>.Empty)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/ValueObjects/ValueObjectSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2323
.Collect()
2424
.SelectMany(static (states, _) => states.Distinct());
2525

26-
var generators = context.MetadataReferencesProvider
26+
var generators = context.GetMetadataReferencesProvider()
2727
.SelectMany(static (reference, _) => TryGetCodeGeneratorFactory(reference, out var factory)
2828
? ImmutableArray.Create(factory)
2929
: ImmutableArray<ICodeGeneratorFactory<ValueObjectSourceGeneratorState>>.Empty)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Immutable;
2+
using Microsoft.CodeAnalysis;
3+
4+
namespace Thinktecture;
5+
6+
public static class IncrementalGeneratorInitializationContextExtensions
7+
{
8+
public static IncrementalValuesProvider<MetadataReference> GetMetadataReferencesProvider(this IncrementalGeneratorInitializationContext context)
9+
{
10+
var metadataProviderProperty = context.GetType().GetProperty(nameof(context.MetadataReferencesProvider))
11+
?? throw new Exception($"The property '{nameof(context.MetadataReferencesProvider)}' not found");
12+
13+
var metadataProvider = metadataProviderProperty.GetValue(context);
14+
15+
if (metadataProvider is IncrementalValuesProvider<MetadataReference> metadataValuesProvider)
16+
return metadataValuesProvider;
17+
18+
if (metadataProvider is IncrementalValueProvider<MetadataReference> metadataValueProvider)
19+
return metadataValueProvider.SelectMany(static (reference, _) => ImmutableArray.Create(reference));
20+
21+
throw new Exception($"The '{nameof(context.MetadataReferencesProvider)}' is neither an 'IncrementalValuesProvider<{nameof(MetadataReference)}>' nor an 'IncrementalValueProvider<{nameof(MetadataReference)}>.'");
22+
}
23+
}

src/Thinktecture.Runtime.Extensions.SourceGenerator/Thinktecture.Runtime.Extensions.SourceGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<IncludeSymbols>false</IncludeSymbols>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" PrivateAssets="all" />
1212

1313
<Compile Include="..\..\shared\IsExternalInit.cs">
1414
<Link>IsExternalInit.cs</Link>

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/Thinktecture.Runtime.Extensions.SourceGenerator.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
1515
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1" />
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="1.1.1" />
17-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" />
1818
</ItemGroup>
1919

2020
</Project>

0 commit comments

Comments
 (0)