Skip to content

Commit 207d457

Browse files
committed
chore: fix RunTimeExtractConstructorArgumentValues for arrays and cleanup
1 parent e2254e1 commit 207d457

File tree

9 files changed

+82
-65
lines changed

9 files changed

+82
-65
lines changed

sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj

-25
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,4 @@
6565
<ProjectReference Include="..\..\src\Atc.Wpf.Theming\Atc.Wpf.Theming.csproj" />
6666
</ItemGroup>
6767

68-
<ItemGroup>
69-
<Folder Include="Resource\" />
70-
</ItemGroup>
71-
72-
<ItemGroup>
73-
<Compile Update="Resource\Word.Designer.cs">
74-
<DesignTime>True</DesignTime>
75-
<AutoGen>True</AutoGen>
76-
<DependentUpon>Word.resx</DependentUpon>
77-
</Compile>
78-
</ItemGroup>
79-
80-
<ItemGroup>
81-
<EmbeddedResource Update="Resource\Word.da-DK.resx">
82-
<Generator>PublicResXFileCodeGenerator</Generator>
83-
</EmbeddedResource>
84-
<EmbeddedResource Update="Resource\Word.de-DE.resx">
85-
<Generator>PublicResXFileCodeGenerator</Generator>
86-
</EmbeddedResource>
87-
<EmbeddedResource Update="Resource\Word.resx">
88-
<Generator>PublicResXFileCodeGenerator</Generator>
89-
<LastGenOutput>Word.Designer.cs</LastGenOutput>
90-
</EmbeddedResource>
91-
</ItemGroup>
92-
9368
</Project>

sample/Atc.Wpf.Sample/SamplesWpfControls/Monitoring/ApplicationMonitorView.xaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8-
xmlns:monitoring="clr-namespace:Atc.Wpf.Controls.Monitoring;assembly=Atc.Wpf.Controls"
98
xmlns:sample="clr-namespace:Atc.Wpf.Sample.SamplesWpfControls.Monitoring"
109
d:DataContext="{d:DesignInstance Type=sample:ApplicationMonitorView}"
1110
d:DesignHeight="600"
@@ -74,7 +73,7 @@
7473

7574
<GroupBox Header="Usage">
7675

77-
<monitoring:ApplicationMonitorView
76+
<atc:ApplicationMonitorView
7877
DataContext="{Binding Path=ApplicationMonitorViewModel}"
7978
ShowAutoScrollInToolbar="{Binding ElementName=ShowAutoScrollInToolbar, Path=IsChecked}"
8079
ShowClearInToolbar="{Binding ElementName=ShowClearInToolbar, Path=IsChecked}"

src/Atc.Wpf.Controls/AssemblyInfo.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Dialogs")]
88
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.LabelControls")]
99
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Layouts")]
10+
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Monitoring")]
1011
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Notifications")]
1112
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Progressing")]
1213
[assembly: XmlnsDefinition("https://github.com/atc-net/atc-wpf/tree/main/schemas", "Atc.Wpf.Controls.Viewers")]

src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<AutoGen>True</AutoGen>
7575
<DependentUpon>Validations.resx</DependentUpon>
7676
</Compile>
77+
<Compile Update="Resources\Word.Designer.cs">
78+
<DependentUpon>Word.resx</DependentUpon>
79+
<DesignTime>True</DesignTime>
80+
<AutoGen>True</AutoGen>
81+
</Compile>
7782
</ItemGroup>
7883

7984
<ItemGroup>
@@ -99,6 +104,16 @@
99104
<Generator>PublicResXFileCodeGenerator</Generator>
100105
<LastGenOutput>Validations.Designer.cs</LastGenOutput>
101106
</EmbeddedResource>
107+
<EmbeddedResource Update="Resources\Word.da-DK.resx">
108+
<Generator>PublicResXFileCodeGenerator</Generator>
109+
</EmbeddedResource>
110+
<EmbeddedResource Update="Resources\Word.de-DE.resx">
111+
<Generator>PublicResXFileCodeGenerator</Generator>
112+
</EmbeddedResource>
113+
<EmbeddedResource Update="Resources\Word.resx">
114+
<LastGenOutput>Word.Designer.cs</LastGenOutput>
115+
<Generator>PublicResXFileCodeGenerator</Generator>
116+
</EmbeddedResource>
102117
</ItemGroup>
103118

104119
</Project>

sample/Atc.Wpf.Sample/Resource/Word.Designer.cs src/Atc.Wpf.Controls/Resources/Word.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Atc.Wpf.SourceGenerators/Extensions/CodeAnalysis/AttributeDataExtensions.cs

+63-36
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ namespace Atc.Wpf.SourceGenerators.Extensions.CodeAnalysis;
22

33
internal static class AttributeDataExtensions
44
{
5+
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "OK.")]
56
public static Dictionary<string, string?> ExtractConstructorArgumentValues(
67
this AttributeData attributeData)
78
{
8-
var result = new Dictionary<string, string?>(StringComparer.Ordinal);
9-
109
if (attributeData.ConstructorArguments.Length == 0 &&
1110
attributeData.NamedArguments.Length == 0)
1211
{
1312
// Syntax check
1413
if (attributeData.ApplicationSyntaxReference is not null)
1514
{
16-
result = attributeData
15+
return attributeData
1716
.ApplicationSyntaxReference
1817
.GetSyntax()
1918
.ToFullString()
@@ -23,41 +22,10 @@ internal static class AttributeDataExtensions
2322
else
2423
{
2524
// Runtime check
26-
var arrayIndex = 0;
27-
foreach (var arg in attributeData.ConstructorArguments)
28-
{
29-
if (arg.Kind == TypedConstantKind.Array)
30-
{
31-
foreach (var typedConstant in arg.Values)
32-
{
33-
if (typedConstant.Value is null)
34-
{
35-
continue;
36-
}
37-
38-
arrayIndex++;
39-
result.Add(
40-
arrayIndex.ToString(CultureInfo.InvariantCulture),
41-
typedConstant.Value.ToString());
42-
}
43-
}
44-
else if (arg.Value is not null)
45-
{
46-
result.Add(
47-
NameConstants.Name,
48-
arg.Value.ToString());
49-
}
50-
}
51-
52-
foreach (var arg in attributeData.NamedArguments)
53-
{
54-
result.Add(
55-
arg.Key,
56-
arg.Value.Value?.ToString());
57-
}
25+
return RunTimeExtractConstructorArgumentValues(attributeData);
5826
}
5927

60-
return result;
28+
return new Dictionary<string, string?>(StringComparer.Ordinal);
6129
}
6230

6331
public static string ExtractClassFirstArgumentType(
@@ -80,4 +48,63 @@ public static string ExtractClassFirstArgumentType(
8048

8149
return type;
8250
}
51+
52+
private static Dictionary<string, string?> RunTimeExtractConstructorArgumentValues(
53+
AttributeData attributeData)
54+
{
55+
var result = new Dictionary<string, string?>(StringComparer.Ordinal);
56+
57+
var arrayIndex = 0;
58+
foreach (var arg in attributeData.ConstructorArguments)
59+
{
60+
if (arg.Kind == TypedConstantKind.Array)
61+
{
62+
foreach (var typedConstant in arg.Values)
63+
{
64+
if (typedConstant.Value is null)
65+
{
66+
continue;
67+
}
68+
69+
arrayIndex++;
70+
result.Add(
71+
arrayIndex.ToString(CultureInfo.InvariantCulture),
72+
typedConstant.Value.ToString());
73+
}
74+
}
75+
else if (arg.Value is not null)
76+
{
77+
result.Add(
78+
NameConstants.Name,
79+
arg.Value.ToString());
80+
}
81+
}
82+
83+
foreach (var arg in attributeData.NamedArguments)
84+
{
85+
if (arg.Value.Kind == TypedConstantKind.Array)
86+
{
87+
foreach (var typedConstant in arg.Value.Values)
88+
{
89+
if (typedConstant.Value is null)
90+
{
91+
continue;
92+
}
93+
94+
arrayIndex++;
95+
result.Add(
96+
arrayIndex.ToString(CultureInfo.InvariantCulture),
97+
typedConstant.Value.ToString());
98+
}
99+
}
100+
else
101+
{
102+
result.Add(
103+
arg.Key,
104+
arg.Value.Value?.ToString());
105+
}
106+
}
107+
108+
return result;
109+
}
83110
}

0 commit comments

Comments
 (0)