Skip to content
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

Add ConfigurationPath property #14

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TestWebApiGenerator;

internal static partial class ServiceRegistrationExtensions
{
[GenerateConfiguration("Services", ExcludedSections = new[] { "Hsts" }, ImplicitSuffixes = new[] { "Instrumentation", "Exporter" })]
[GenerateConfiguration("Services", ExcludedSections = new[] { "Hsts" }, ImplicitSuffixes = new[] { "Instrumentation", "Exporter" }, ConfigurationPath = nameof(WebApplicationBuilder.Configuration))]
public static partial void AddServicesFromConfiguration(this WebApplicationBuilder builder);

// [GenerateServiceRegistration("Services")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public GenerateConfigurationAttribute(string configurationSection)
/// </summary>
public string ConfigurationFile { get; set; } = DefaultConfigurationFile;

/// <summary>
/// The configuration path.
/// </summary>
public string? ConfigurationPath { get; set; }

/// <summary>
/// Sections to exclude.
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/ConfigurationProcessor.SourceGeneration/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal IReadOnlyList<ServiceRegistrationClass> GetServiceRegistrationClasses(I

IMethodSymbol? configurationMethodSymbol = sm.GetDeclaredSymbol(method, cancellationToken)!;
Debug.Assert(configurationMethodSymbol != null, "configuration method is present.");
(string configurationSection, string? configurationFile) = (string.Empty, null);
(string configurationSection, string? configurationFile, string? configurationPath) = (string.Empty, null, null);
string[] excluded = Array.Empty<string>();
string[] suffixes = Array.Empty<string>();
foreach (AttributeListSyntax mal in method.AttributeLists)
Expand Down Expand Up @@ -157,6 +157,9 @@ internal IReadOnlyList<ServiceRegistrationClass> GetServiceRegistrationClasses(I
case "ConfigurationFile":
configurationFile = (string?)GetItem(value);
break;
case "ConfigurationPath":
configurationPath = (string?)GetItem(value);
break;
case "ExcludedSections":
var values = (ImmutableArray<TypedConstant>)GetItem(value)!;
excluded = values.Select(x => $"{configurationSection}:{x.Value}").ToArray();
Expand Down Expand Up @@ -357,6 +360,11 @@ static string ToDisplay(IParameterSymbol parameter)
foundTarget = false;
}

if (!string.IsNullOrEmpty(configurationPath))
{
lm.ConfigurationField = $"{paramName}.{configurationPath}";
}

var properties = paramTypeSymbol.GetMembers().OfType<IPropertySymbol>().ToArray();
foreach (var property in properties)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Generator')) OR $(MSBuildProjectName.EndsWith('.SourceGeneration'))">
<Version>0.4.0</Version>
<Version>0.4.1</Version>
<PackageVersion>$(Version)-beta.1</PackageVersion>
</PropertyGroup>

Expand Down
Loading