Skip to content

Commit e47e9be

Browse files
committed
start digging into roslyn for icon enum generation
1 parent 95a6a47 commit e47e9be

File tree

4 files changed

+108
-9
lines changed

4 files changed

+108
-9
lines changed

mdresgen/IconThing.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
using System.Text;
77
using System.Threading.Tasks;
88
using Humanizer;
9+
using Microsoft.CodeAnalysis;
10+
using Microsoft.CodeAnalysis.CSharp;
11+
using Microsoft.CodeAnalysis.CSharp.Syntax;
12+
using Microsoft.CodeAnalysis.Text;
913
using Newtonsoft.Json.Linq;
1014

1115
namespace mdresgen
@@ -14,15 +18,17 @@ class IconThing
1418
{
1519
public void Run()
1620
{
17-
var nameDataPairs = GetNameDataPairs(GetSourceData()).ToList();
21+
Console.WriteLine("Downloading icon data...");
22+
23+
//var nameDataPairs = GetNameDataPairs(GetSourceData()).ToList();
24+
25+
// Console.WriteLine(nameDataPairs.Count);
1826

19-
Console.WriteLine(nameDataPairs.Count);
27+
UpdateEnum("IconType.template.cs");
2028
}
2129

2230
private static string GetSourceData()
2331
{
24-
Console.WriteLine("Downloading icon data...");
25-
2632
var webRequest = WebRequest.CreateDefault(
2733
new Uri("https://materialdesignicons.com/api/package/38EF63D0-4744-11E4-B3CF-842B2B6CFE1B"));
2834
webRequest.UseDefaultCredentials = true;
@@ -44,12 +50,25 @@ private static IEnumerable<Tuple<string, string>> GetNameDataPairs(string source
4450
t["data"].ToString()));
4551
}
4652

47-
4853

49-
private void UpdateEnum()
54+
55+
private void UpdateEnum(string sourceFile)
5056
{
51-
//SyntaxNode
57+
var sourceText = SourceText.From(new FileStream(sourceFile, FileMode.Open));
58+
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText);
59+
60+
var enumDeclarationSyntax = syntaxTree.GetRoot().ChildNodes()
61+
//should be the root name space
62+
.Single()
63+
.ChildNodes().OfType<EnumDeclarationSyntax>()
64+
.Last();
65+
66+
var enumMemberDeclarationSyntax = enumDeclarationSyntax.ChildNodes().OfType<EnumMemberDeclarationSyntax>().Single();
67+
68+
69+
70+
5271
}
53-
72+
5473
}
5574
}

mdresgen/IconType.template.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace MaterialDesignThemes.Wpf
22
{
3+
/// ******************************************
4+
/// This code is auto generated. Do not amend.
5+
/// ******************************************
6+
37
/// <summary>
48
/// List of available icons for use with <see cref="Icon"/>.
59
/// </summary>
@@ -9,6 +13,7 @@ namespace MaterialDesignThemes.Wpf
913
/// </remarks>
1014
public enum IconType
1115
{
12-
AutoGeneratedDoNotAmend
16+
AutoGenerated,
17+
DoNotAmend
1318
}
1419
}

mdresgen/mdresgen.csproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,61 @@
4848
<HintPath>..\packages\Humanizer.1.37.7\lib\portable-win+net40+sl50+wp8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Humanizer.dll</HintPath>
4949
<Private>True</Private>
5050
</Reference>
51+
<Reference Include="Microsoft.CodeAnalysis, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
53+
<Private>True</Private>
54+
</Reference>
55+
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
56+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.1.1.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
57+
<Private>True</Private>
58+
</Reference>
59+
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
60+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.1.1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
61+
<Private>True</Private>
62+
</Reference>
63+
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64+
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
68+
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
5171
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5272
<SpecificVersion>False</SpecificVersion>
5373
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
5474
</Reference>
5575
<Reference Include="System" />
76+
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
77+
<HintPath>..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll</HintPath>
78+
<Private>True</Private>
79+
</Reference>
80+
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
81+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
82+
<Private>True</Private>
83+
</Reference>
84+
<Reference Include="System.Composition.Convention, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
85+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll</HintPath>
86+
<Private>True</Private>
87+
</Reference>
88+
<Reference Include="System.Composition.Hosting, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
89+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll</HintPath>
90+
<Private>True</Private>
91+
</Reference>
92+
<Reference Include="System.Composition.Runtime, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
93+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll</HintPath>
94+
<Private>True</Private>
95+
</Reference>
96+
<Reference Include="System.Composition.TypedParts, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
97+
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
98+
<Private>True</Private>
99+
</Reference>
56100
<Reference Include="System.Core" />
57101
<Reference Include="System.Drawing" />
102+
<Reference Include="System.Reflection.Metadata, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
103+
<HintPath>..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\System.Reflection.Metadata.dll</HintPath>
104+
<Private>True</Private>
105+
</Reference>
58106
<Reference Include="System.Xml.Linq" />
59107
<Reference Include="System.Data.DataSetExtensions" />
60108
<Reference Include="Microsoft.CSharp" />
@@ -90,6 +138,10 @@
90138
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
91139
</None>
92140
</ItemGroup>
141+
<ItemGroup>
142+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
143+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
144+
</ItemGroup>
93145
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
94146
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
95147
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

mdresgen/packages.config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Humanizer" version="1.37.7" targetFramework="net45" />
4+
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net45" />
5+
<package id="Microsoft.CodeAnalysis.Common" version="1.1.1" targetFramework="net45" />
6+
<package id="Microsoft.CodeAnalysis.CSharp" version="1.1.1" targetFramework="net45" />
7+
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.1.1" targetFramework="net45" />
8+
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.1.1" targetFramework="net45" />
9+
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
410
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
11+
<package id="System.Collections" version="4.0.0" targetFramework="net45" />
12+
<package id="System.Collections.Immutable" version="1.1.37" targetFramework="net45" />
13+
<package id="System.Diagnostics.Debug" version="4.0.0" targetFramework="net45" />
14+
<package id="System.Globalization" version="4.0.0" targetFramework="net45" />
15+
<package id="System.IO" version="4.0.0" targetFramework="net45" />
16+
<package id="System.Linq" version="4.0.0" targetFramework="net45" />
17+
<package id="System.Reflection" version="4.0.0" targetFramework="net45" />
18+
<package id="System.Reflection.Extensions" version="4.0.0" targetFramework="net45" />
19+
<package id="System.Reflection.Metadata" version="1.1.0" targetFramework="net45" />
20+
<package id="System.Reflection.Primitives" version="4.0.0" targetFramework="net45" />
21+
<package id="System.Resources.ResourceManager" version="4.0.0" targetFramework="net45" />
22+
<package id="System.Runtime" version="4.0.0" targetFramework="net45" />
23+
<package id="System.Runtime.Extensions" version="4.0.0" targetFramework="net45" />
24+
<package id="System.Runtime.InteropServices" version="4.0.0" targetFramework="net45" />
25+
<package id="System.Text.Encoding" version="4.0.0" targetFramework="net45" />
26+
<package id="System.Text.Encoding.Extensions" version="4.0.0" targetFramework="net45" />
27+
<package id="System.Threading" version="4.0.0" targetFramework="net45" />
528
</packages>

0 commit comments

Comments
 (0)