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

chore: fix RunTimeExtractConstructorArgumentValues for arrays and cle… #144

Merged
merged 1 commit into from
Mar 16, 2025
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
25 changes: 0 additions & 25 deletions sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,4 @@
<ProjectReference Include="..\..\src\Atc.Wpf.Theming\Atc.Wpf.Theming.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Resource\" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resource\Word.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Word.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resource\Word.da-DK.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resource\Word.de-DE.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resource\Word.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Word.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:monitoring="clr-namespace:Atc.Wpf.Controls.Monitoring;assembly=Atc.Wpf.Controls"
xmlns:sample="clr-namespace:Atc.Wpf.Sample.SamplesWpfControls.Monitoring"
d:DataContext="{d:DesignInstance Type=sample:ApplicationMonitorView}"
d:DesignHeight="600"
Expand Down Expand Up @@ -74,7 +73,7 @@

<GroupBox Header="Usage">

<monitoring:ApplicationMonitorView
<atc:ApplicationMonitorView
DataContext="{Binding Path=ApplicationMonitorViewModel}"
ShowAutoScrollInToolbar="{Binding ElementName=ShowAutoScrollInToolbar, Path=IsChecked}"
ShowClearInToolbar="{Binding ElementName=ShowClearInToolbar, Path=IsChecked}"
Expand Down
1 change: 1 addition & 0 deletions src/Atc.Wpf.Controls/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Monitoring")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]
15 changes: 15 additions & 0 deletions src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Validations.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Word.Designer.cs">
<DependentUpon>Word.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -99,6 +104,16 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Validations.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Word.da-DK.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Word.de-DE.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Word.resx">
<LastGenOutput>Word.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ namespace Atc.Wpf.SourceGenerators.Extensions.CodeAnalysis;

internal static class AttributeDataExtensions
{
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")]
public static Dictionary<string, string?> ExtractConstructorArgumentValues(
this AttributeData attributeData)
{
var result = new Dictionary<string, string?>(StringComparer.Ordinal);

if (attributeData.ConstructorArguments.Length == 0 &&
attributeData.NamedArguments.Length == 0)
{
// Syntax check
if (attributeData.ApplicationSyntaxReference is not null)
{
result = attributeData
return attributeData
.ApplicationSyntaxReference
.GetSyntax()
.ToFullString()
Expand All @@ -23,41 +22,10 @@ internal static class AttributeDataExtensions
else
{
// Runtime check
var arrayIndex = 0;
foreach (var arg in attributeData.ConstructorArguments)
{
if (arg.Kind == TypedConstantKind.Array)
{
foreach (var typedConstant in arg.Values)
{
if (typedConstant.Value is null)
{
continue;
}

arrayIndex++;
result.Add(
arrayIndex.ToString(CultureInfo.InvariantCulture),
typedConstant.Value.ToString());
}
}
else if (arg.Value is not null)
{
result.Add(
NameConstants.Name,
arg.Value.ToString());
}
}

foreach (var arg in attributeData.NamedArguments)
{
result.Add(
arg.Key,
arg.Value.Value?.ToString());
}
return RunTimeExtractConstructorArgumentValues(attributeData);
}

return result;
return new Dictionary<string, string?>(StringComparer.Ordinal);
}

public static string ExtractClassFirstArgumentType(
Expand All @@ -80,4 +48,63 @@ public static string ExtractClassFirstArgumentType(

return type;
}

private static Dictionary<string, string?> RunTimeExtractConstructorArgumentValues(
AttributeData attributeData)
{
var result = new Dictionary<string, string?>(StringComparer.Ordinal);

var arrayIndex = 0;
foreach (var arg in attributeData.ConstructorArguments)
{
if (arg.Kind == TypedConstantKind.Array)
{
foreach (var typedConstant in arg.Values)
{
if (typedConstant.Value is null)
{
continue;
}

arrayIndex++;
result.Add(
arrayIndex.ToString(CultureInfo.InvariantCulture),
typedConstant.Value.ToString());
}
}
else if (arg.Value is not null)
{
result.Add(
NameConstants.Name,
arg.Value.ToString());
}
}

foreach (var arg in attributeData.NamedArguments)
{
if (arg.Value.Kind == TypedConstantKind.Array)
{
foreach (var typedConstant in arg.Value.Values)
{
if (typedConstant.Value is null)
{
continue;
}

arrayIndex++;
result.Add(
arrayIndex.ToString(CultureInfo.InvariantCulture),
typedConstant.Value.ToString());
}
}
else
{
result.Add(
arg.Key,
arg.Value.Value?.ToString());
}
}

return result;
}
}
Loading