<#@ template debug="false" hostspecific="true" language="C#" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.IO" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.Text.RegularExpressions" #> <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #> <#@ assembly name="$(ProjectDir)\Resources\DLLs\IconResourcesGenerator.dll" #> <#@ import namespace="IconResourcesGenerator" #> <#@ output extension=".cs" encoding="utf-8" #> <# ITextTemplatingEngineHost host = this.Host; string jsPath = host.ResolvePath("iconfont.js"); string cssPath = host.ResolvePath("iconfont.css"); string namespaceName = "PipeReviewReport.Resources.Fonts"; Generator generator = new Generator(jsPath, cssPath); Dictionary glyphToKey = generator.ExecuteGlyphToKey(); Dictionary keyToGlyph = generator.ExecuteKeyToGlyph(); (Dictionary simpleNameToKey, Dictionary keyToSimpleName) = generator.ExecuteSimpleNameToKey(); #> using System; // using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Media; namespace <#= namespaceName #>; [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "")] internal class __________________Temp__________________ { [SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "")] private void Test() { } }; /// /// 图标名称枚举 /// // [TypeConverter(typeof(EnumConverter))] public enum IconNameEnum { Empty, <# foreach (var entry in simpleNameToKey) { #> /// /// <#= keyToGlyph[entry.Value] #> ///
/// icon-<#= entry.Value #> ///
<#= entry.Key #>, <# } #> } public static class IconNameEnumExtensions { /// /// 根据图标名称枚举获取 Key /// /// 图标名称枚举 /// 注册到资源中的 Key /// public static string GetKey(this IconNameEnum e) { return e switch { IconNameEnum.Empty => null, <# foreach (var entry in simpleNameToKey) { #> IconNameEnum.<#= entry.Key #> => "icon-<#= entry.Value #>", <# } #> _ => throw new NotImplementedException(), }; } /// /// 根据图标名称获取 Glyph 枚举 /// /// 图标名称枚举 /// 图标 Glyph 枚举 /// public static IconGlyphEnum GetGlyphEnum(this IconNameEnum e) { return e switch { IconNameEnum.Empty => IconGlyphEnum.Empty, <# foreach (var entry in simpleNameToKey) { #> IconNameEnum.<#= entry.Key #> => IconGlyphEnum.<#= keyToGlyph[entry.Value] #>, <# } #> _ => throw new NotImplementedException(), }; } /// /// 根据图标名称获取 Glyph 字符串 /// /// 图标名称枚举 /// 图标 Glyph 字符串 /// public static string GetGlyphString(this IconNameEnum e) { return e switch { IconNameEnum.Empty => string.Empty, <# foreach (var entry in simpleNameToKey) { #> IconNameEnum.<#= entry.Key #> => "\u<#= keyToGlyph[entry.Value] #>", <# } #> _ => throw new NotImplementedException(), }; } public static string GetImageSourceKey(this IconNameEnum e) { return GetKey(e) + "_Image"; } } /// /// 图标 Glyph 枚举 /// // [TypeConverter(typeof(EnumConverter))] public enum IconGlyphEnum { Empty, <# foreach (var entry in glyphToKey) { #> /// /// <#= keyToSimpleName[entry.Value] #> ///
/// icon-<#= entry.Value #> ///
<#= entry.Key #>, <# } #> } public static class IconGlyphEnumExtensions { /// /// 根据 Glyph 枚举获取 Key /// /// Glyph 枚举 /// 注册到资源中的 Key /// public static string GetKey(this IconGlyphEnum e) { return e switch { IconGlyphEnum.Empty => null, <# foreach (var entry in glyphToKey) { #> IconGlyphEnum.<#= entry.Key #> => "icon-<#= entry.Value #>", <# } #> _ => throw new NotImplementedException(), }; } /// /// 根据图标 Glyph 枚举获取图标名称枚举 /// /// 图标 Glyph 枚举 /// 图标名称枚举 /// public static IconNameEnum GetNameEnum(this IconGlyphEnum e) { return e switch { IconGlyphEnum.Empty => IconNameEnum.Empty, <# foreach (var entry in glyphToKey) { #> IconGlyphEnum.<#= entry.Key #> => IconNameEnum.<#= keyToSimpleName[entry.Value] #>, <# } #> _ => throw new NotImplementedException(), }; } /// /// 根据图标 Glyph 枚举获取 Glyph 字符串 /// /// 图标 Glyph 枚举 /// 图标 Glyph 字符串 /// public static string GetGlyphString(this IconGlyphEnum e) { return e switch { IconGlyphEnum.Empty => string.Empty, <# foreach (var entry in glyphToKey) { #> IconGlyphEnum.<#= entry.Key #> => "\u<#= keyToGlyph[entry.Value] #>", <# } #> _ => throw new NotImplementedException(), }; } public static string GetImageSourceKey(this IconGlyphEnum e) { return GetKey(e) + "_Image"; } } public class IconEnumNameToGlyphConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is IconNameEnum nameEnum) { return nameEnum.GetGlyphEnum(); } return DependencyProperty.UnsetValue; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is IconGlyphEnum glyphEnum) { return glyphEnum.GetNameEnum(); } return DependencyProperty.UnsetValue; } } public class IconGlyphNameToNameConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is IconGlyphEnum glyphEnum) { return glyphEnum.GetNameEnum(); } return DependencyProperty.UnsetValue; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is IconNameEnum nameEnum) { return nameEnum.GetGlyphEnum(); } return DependencyProperty.UnsetValue; } }