-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Create source generator for configuration binding #82179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cadfb5d
09a086c
acbd7cd
32be0a4
16e3abe
490c00d
f4ade82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project> | ||
<Target Name="_{TargetPrefix}GatherAnalyzers"> | ||
<ItemGroup> | ||
<_{TargetPrefix}Analyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == '{NuGetPackageId}'" /> | ||
</ItemGroup> | ||
</Target> | ||
layomia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<Target Name="_{TargetPrefix}RemoveAnalyzer" | ||
Condition="'$({EnableSourceGeneratorPropertyName})' != 'true'" | ||
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets" | ||
DependsOnTargets="_{TargetPrefix}GatherAnalyzers"> | ||
|
||
<ItemGroup> | ||
<Analyzer Remove="@(_{TargetPrefix}Analyzer)" /> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration | ||
{ | ||
internal abstract record CollectionSpec : TypeSpec | ||
{ | ||
public CollectionSpec(ITypeSymbol type) : base(type) | ||
{ | ||
IsReadOnly = type.IsReadOnly; | ||
IsInterface = type is INamedTypeSymbol { TypeKind: TypeKind.Interface }; | ||
} | ||
|
||
public required TypeSpec ElementType { get; init; } | ||
|
||
public bool IsReadOnly { get; } | ||
|
||
public bool IsInterface { get; } | ||
|
||
public CollectionSpec? ConcreteType { get; init; } | ||
} | ||
|
||
internal sealed record EnumerableSpec : CollectionSpec | ||
{ | ||
public EnumerableSpec(ITypeSymbol type) : base(type) { } | ||
|
||
public override TypeSpecKind SpecKind { get; init; } = TypeSpecKind.Enumerable; | ||
} | ||
|
||
internal sealed record DictionarySpec : CollectionSpec | ||
{ | ||
public DictionarySpec(INamedTypeSymbol type) : base(type) { } | ||
|
||
public override TypeSpecKind SpecKind => TypeSpecKind.Dictionary; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends: if it is converted into an auto-property then it will be part of the record's equality comparison implementation. FWIW the equality comparison generated for C# records does take polymorphism into account, so you wouldn't need to take the "kind" into account: |
||
|
||
public required TypeSpec KeyType { get; init; } | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.