Skip to content

Commit e8513f7

Browse files
authored
Fixing resource generator (#2171)
* Adding resource generator * Fixing nullable reference types
1 parent e256995 commit e8513f7

9 files changed

+80
-66
lines changed

Directory.packages.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<Project>
22
<ItemGroup>
33
<PackageVersion Include="Dragablz" Version="0.0.3.223" />
4+
<PackageVersion Include="Humanizer" Version="2.8.26" />
45
<PackageVersion Include="MahApps.Metro" Version="2.3.0" />
6+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0" PrivateAssets="all" />
7+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="3.7.0" />
8+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="3.7.0" />
9+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" />
10+
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.7.0" />
11+
<PackageVersion Include="Microsoft.Composition" Version="1.0.31" />
512
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
613
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="5.0.0" />
714
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
15+
<PackageVersion Include="Newtonsoft.Json" Version="12.0.3" />
816
<PackageVersion Include="Shouldly" Version="3.0.2" />
917
<PackageVersion Include="ShowMeTheXAML" Version="2.0.0" />
1018
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />

MaterialDesignThemes.MahApps/MaterialDesignThemes.MahApps.csproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
3-
<PropertyGroup>
4-
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
5-
<UseWPF>true</UseWPF>
6-
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
7-
<MDIXMahAppsVersion Condition="$(MDIXMahAppsVersion) == '' Or $(MDIXMahAppsVersion) == '*Undefined*'">1.0.1</MDIXMahAppsVersion>
8-
<AssemblyTitle>MaterialDesignThemes.MahApps</AssemblyTitle>
9-
<Product>MaterialDesignThemes.MahApps</Product>
10-
<Version>$(MDIXMahAppsVersion)</Version>
11-
<AssemblyVersion>$(MDIXMahAppsVersion)</AssemblyVersion>
12-
<ExtrasEnableWpfProjectSetup>true</ExtrasEnableWpfProjectSetup>
13-
<UseWPF>true</UseWPF>
14-
</PropertyGroup>
15-
<ItemGroup>
16-
<ProjectReference Include="..\MaterialDesignColors.Wpf\MaterialDesignColors.Wpf.csproj" />
17-
<ProjectReference Include="..\MaterialDesignThemes.Wpf\MaterialDesignThemes.Wpf.csproj" />
18-
</ItemGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
5+
<UseWPF>true</UseWPF>
6+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
7+
<MDIXMahAppsVersion Condition="$(MDIXMahAppsVersion) == '' Or $(MDIXMahAppsVersion) == '*Undefined*'">1.0.1</MDIXMahAppsVersion>
8+
<AssemblyTitle>MaterialDesignThemes.MahApps</AssemblyTitle>
9+
<Product>MaterialDesignThemes.MahApps</Product>
10+
<Version>$(MDIXMahAppsVersion)</Version>
11+
<AssemblyVersion>$(MDIXMahAppsVersion)</AssemblyVersion>
12+
<ExtrasEnableWpfProjectSetup>true</ExtrasEnableWpfProjectSetup>
13+
<UseWPF>true</UseWPF>
14+
</PropertyGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="..\MaterialDesignColors.Wpf\MaterialDesignColors.Wpf.csproj" />
17+
<ProjectReference Include="..\MaterialDesignThemes.Wpf\MaterialDesignThemes.Wpf.csproj" />
18+
</ItemGroup>
1919
<ItemGroup>
2020
<PackageReference Include="MahApps.Metro" />
2121
</ItemGroup>

MaterialDesignToolkit.Full.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialDesignThemes.UITest
4444
{CF0A27A8-EF82-44E5-B673-ECCC150C48ED} = {CF0A27A8-EF82-44E5-B673-ECCC150C48ED}
4545
EndProjectSection
4646
EndProject
47+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{9E303A4A-3712-44B9-91EE-830FDC087795}"
48+
EndProject
49+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mdresgen", "mdresgen\mdresgen.csproj", "{59CE50AC-D176-4CC0-B465-26F66054A15E}"
50+
EndProject
4751
Global
4852
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4953
Debug|Any CPU = Debug|Any CPU
@@ -184,13 +188,30 @@ Global
184188
{594D2254-3623-4088-A8BD-D74B6E96DE9F}.Release|x64.Build.0 = Release|Any CPU
185189
{594D2254-3623-4088-A8BD-D74B6E96DE9F}.Release|x86.ActiveCfg = Release|Any CPU
186190
{594D2254-3623-4088-A8BD-D74B6E96DE9F}.Release|x86.Build.0 = Release|Any CPU
191+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
192+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|Any CPU.Build.0 = Debug|Any CPU
193+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|ARM.ActiveCfg = Debug|Any CPU
194+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|ARM.Build.0 = Debug|Any CPU
195+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|x64.ActiveCfg = Debug|Any CPU
196+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|x64.Build.0 = Debug|Any CPU
197+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|x86.ActiveCfg = Debug|Any CPU
198+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Debug|x86.Build.0 = Debug|Any CPU
199+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|Any CPU.ActiveCfg = Release|Any CPU
200+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|Any CPU.Build.0 = Release|Any CPU
201+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|ARM.ActiveCfg = Release|Any CPU
202+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|ARM.Build.0 = Release|Any CPU
203+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|x64.ActiveCfg = Release|Any CPU
204+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|x64.Build.0 = Release|Any CPU
205+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|x86.ActiveCfg = Release|Any CPU
206+
{59CE50AC-D176-4CC0-B465-26F66054A15E}.Release|x86.Build.0 = Release|Any CPU
187207
EndGlobalSection
188208
GlobalSection(SolutionProperties) = preSolution
189209
HideSolutionNode = FALSE
190210
EndGlobalSection
191211
GlobalSection(NestedProjects) = preSolution
192212
{CF0A27A8-EF82-44E5-B673-ECCC150C48ED} = {D34BE232-DE51-43C1-ABDC-B69003BB50FF}
193213
{803954E5-3A35-4D8B-95A7-F6E9B63EC0DF} = {D34BE232-DE51-43C1-ABDC-B69003BB50FF}
214+
{59CE50AC-D176-4CC0-B465-26F66054A15E} = {9E303A4A-3712-44B9-91EE-830FDC087795}
194215
EndGlobalSection
195216
GlobalSection(ExtensibilityGlobals) = postSolution
196217
SolutionGuid = {730B2F9E-74AE-46CE-9E61-89AA5C6D5DD3}

MaterialDesignToolkit.ResourceGeneration.sln

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"solution": {
3+
"path": "MaterialDesignToolkit.Full.sln",
4+
"projects": [
5+
"mdresgen\\mdresgen.csproj"
6+
]
7+
}
8+
}

mdresgen/IconThing.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public static void Run()
3636

3737
private static void Write(string content, string filePath)
3838
{
39-
for(string currentDirectory = Path.GetFullPath(".");
39+
for(string? currentDirectory = Path.GetFullPath(".");
4040
!string.IsNullOrEmpty(Path.GetDirectoryName(currentDirectory));
4141
currentDirectory = Path.GetDirectoryName(currentDirectory))
4242
{
43-
string path = Path.Combine(currentDirectory, filePath);
43+
string path = Path.Combine(currentDirectory!, filePath);
4444
if (File.Exists(path))
4545
{
4646
File.WriteAllText(path, content);
@@ -71,9 +71,10 @@ private static IEnumerable<Icon> GetIcons(string sourceData)
7171
var icons = new[] { new Icon("None", string.Empty, new List<string>()) } //Add None value always to Enum at first place
7272
.Concat(
7373
jObject["icons"].Select(t => new Icon(
74-
t["name"].ToString().Underscore().Pascalize(),
75-
t["data"].ToString(),
76-
t["aliases"].ToObject<IEnumerable<string>>().Select(x => x.Underscore().Pascalize()).ToList()))
74+
t["name"]?.ToString().Underscore().Pascalize() ?? throw new Exception("Failed to find name"),
75+
t["data"]?.ToString() ?? throw new Exception("Failed to find data"),
76+
t["aliases"]?.ToObject<IEnumerable<string>>().Select(x => x.Underscore().Pascalize()).ToList()
77+
?? throw new Exception("Failed to find aliases")))
7778
);
7879

7980
var iconsByName = new Dictionary<string, Icon>(StringComparer.OrdinalIgnoreCase);
@@ -135,7 +136,8 @@ private static string UpdateEnum(string sourceFile, IEnumerable<Icon> icons)
135136
var namespaceDeclarationNode = rootNode.ChildNodes().Single();
136137
var enumDeclarationSyntaxNode = namespaceDeclarationNode.ChildNodes().OfType<EnumDeclarationSyntax>().Single();
137138

138-
var emptyEnumDeclarationSyntaxNode = enumDeclarationSyntaxNode.RemoveNodes(enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>(), SyntaxRemoveOptions.KeepDirectives);
139+
var emptyEnumDeclarationSyntaxNode = enumDeclarationSyntaxNode.RemoveNodes(enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>(), SyntaxRemoveOptions.KeepDirectives)
140+
?? throw new Exception("Removed all nodes");
139141

140142
var leadingTriviaList = SyntaxTriviaList.Create(SyntaxFactory.Whitespace(" "));
141143
var enumMemberDeclarationSyntaxs = icons.SelectMany(GetEnumMemberDeclarations).ToArray();
@@ -173,7 +175,7 @@ private static EnumDeclarationSyntax AddLineFeedsToCommas(EnumDeclarationSyntax
173175
.Select(nodeOrToken => nodeOrToken.AsToken())
174176
.FirstOrDefault(
175177
token =>
176-
token.Value.Equals(",") &&
178+
token.Value?.Equals(",") == true &&
177179
(!token.HasTrailingTrivia || !token.TrailingTrivia.Any(SyntaxKind.EndOfLineTrivia)));
178180

179181
SyntaxToken current;

mdresgen/MdPalette.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
{
33
class MdPalette
44
{
5-
public string[] shades { get; set; }
6-
public palette[] palettes { get; set; }
5+
public string[]? shades { get; set; }
6+
public palette[]? palettes { get; set; }
77

88
public class palette
99
{
10-
public string name { get; set; }
11-
public string[] hexes { get; set; }
10+
public string? name { get; set; }
11+
public string[]? hexes { get; set; }
1212
}
1313
}
1414
}

mdresgen/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ static void Main(string[] args)
8080

8181
private static void GenerateClasses(MdPalette palettes)
8282
{
83-
foreach(var palette in palettes.palettes)
83+
foreach(var palette in palettes.palettes ?? Enumerable.Empty<MdPalette.palette>())
8484
{
8585
var sb = new StringBuilder();
8686

8787
var colors = new StringBuilder();
8888
var hueNames = new StringBuilder();
89-
var shortName = palette.name.Replace(" ", "");
89+
var shortName = palette.name?.Replace(" ", "");
9090

91-
for (var i = 0; i < palette.hexes.Length; i++)
91+
for (var i = 0; i < palette.hexes?.Length; i++)
9292
{
93-
var colorName = shortName + palettes.shades[i];
93+
var colorName = shortName + palettes.shades?[i];
9494
colors.AppendLine($"\t\tpublic static Color {colorName} {{ get; }} = (Color)ColorConverter.ConvertFromString(\"{palette.hexes[i]}\");");
9595
hueNames.AppendLine($"\t\t\t{{ MaterialDesignColor.{colorName}, {colorName} }},");
9696
}

mdresgen/mdresgen.csproj

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
7-
<Compile Remove="*.template.cs" />
87
<Content Include="MdPaletteJson.json">
98
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
109
</Content>
11-
<None Include="PackIconDataFactory.template.cs">
12-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
13-
</None>
14-
<None Include="PackIconKind.template.cs">
10+
<Compile Remove="*.template.cs" />
11+
<None Include="*.template.cs">
1512
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1613
</None>
1714
<Content Include="MaterialColourSwatchesSnippet.xml">
@@ -25,13 +22,13 @@
2522
</None>
2623
</ItemGroup>
2724
<ItemGroup>
28-
<PackageReference Include="Humanizer" Version="2.8.26" />
29-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0" PrivateAssets="all" />
30-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.7.0" />
31-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.7.0" />
32-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" />
33-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.7.0" />
34-
<PackageReference Include="Microsoft.Composition" Version="1.0.31" />
35-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
25+
<PackageReference Include="Humanizer" />
26+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
27+
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
28+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
29+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
30+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
31+
<PackageReference Include="Microsoft.Composition" />
32+
<PackageReference Include="Newtonsoft.Json" />
3633
</ItemGroup>
3734
</Project>

0 commit comments

Comments
 (0)