Skip to content

Commit

Permalink
Changed MaterialIconsFontGenerator to use enums with values instead o…
Browse files Browse the repository at this point in the history
…f dictionary lookup.
  • Loading branch information
Felix-CodingClimber committed Jun 30, 2024
1 parent 36c99da commit 4488839
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions src/DotNetElements.Extensions.Icons/MaterialIconsFontGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace DotNetElements.Extensions.Icons;


internal partial class MaterialIconsFontGenerator
{
private readonly HttpClient httpClient;
Expand Down Expand Up @@ -58,67 +57,46 @@ public async Task Run()
return iconSet;
}

private async Task WriteToFileAsync(IReadOnlyList<MaterialIcon> iconInfo)
private static async Task WriteToFileAsync(IReadOnlyList<MaterialIcon> iconInfo)
{
StringBuilder resultBuilder = new();
resultBuilder.AppendLine(fileHeader);

StringBuilder iconBuilder = new();

StringBuilder iconDictionaryBuilder = new();
iconDictionaryBuilder.AppendLine(iconDictionaryHeader);

foreach (MaterialIcon icon in iconInfo)
{
string varName = icon.Id!.ConvertSnakeToPascalCase();

iconBuilder.AppendLine($" {varName},");

iconDictionaryBuilder.AppendLine($" {{ Icons.Material.{varName}, \"&#x{icon.Unicode};\" }},");
iconBuilder.AppendLine($" {varName} = {$"0x{icon.Unicode}"},");
}

resultBuilder.Append(iconBuilder);
resultBuilder.Append(iconDictionaryBuilder);
resultBuilder.Append(fileFooter);

await File.WriteAllTextAsync("MaterialIcons.cs", resultBuilder.ToString());
}

private const string fileHeader =
"""
//----------------------
// <auto-generated>
// Generated by the DotNetElements.Extensions.Icons MaterialIconsFontGenerator. DO NOT EDIT!
// source: MaterialIconsFontGenerator.cs
// </auto-generated>
//----------------------
namespace DotNetElements.Extensions.Icons;
public static partial class Icons
{
public enum Material
{
""";

private const string iconDictionaryHeader =
"""
}
}
public static partial class MaterialIconsExtensions
//----------------------
// <auto-generated>
// Generated by the DotNetElements.Extensions.Icons MaterialIconsFontGenerator. DO NOT EDIT!
// source: MaterialIconsFontGenerator.cs
// </auto-generated>
//----------------------
namespace DotNetElements.Extensions.Icons;
public static partial class Icons
{
private readonly static Dictionary<Icons.Material, string> unicodeMap = new()
{
public enum Material
{
None = 0,
""";

private const string fileFooter =
"""
};
public static string ToUnicode(this Icons.Material materialIcon)
{
return unicodeMap[materialIcon];
}
}
Expand Down

0 comments on commit 4488839

Please # to comment.