Skip to content

Commit

Permalink
Add ConfigurationPath property
Browse files Browse the repository at this point in the history
  • Loading branch information
almostchristian committed Sep 26, 2023
1 parent d5ec76d commit ed1dc7c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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

0 comments on commit ed1dc7c

Please sign in to comment.