Files
Store.Management/Source/Store.Management.Framework/Resources/Fonts/IconEnum.tt
T
2026-11-11 14:33:39 +08:00

284 lines
6.7 KiB
Plaintext

<#@ 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<string, string> glyphToKey = generator.ExecuteGlyphToKey();
Dictionary<string, string> keyToGlyph = generator.ExecuteKeyToGlyph();
(Dictionary<string, string> simpleNameToKey, Dictionary<string, string> 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 = "<Pending>")]
internal class __________________Temp__________________
{
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
private void Test()
{
}
};
/// <summary>
/// 图标名称枚举
/// </summary>
// [TypeConverter(typeof(EnumConverter))]
public enum IconNameEnum
{
Empty,
<#
foreach (var entry in simpleNameToKey)
{
#>
/// <summary>
/// <#= keyToGlyph[entry.Value] #>
/// <br/>
/// icon-<#= entry.Value #>
/// </summary>
<#= entry.Key #>,
<#
}
#>
}
public static class IconNameEnumExtensions
{
/// <summary>
/// 根据图标名称枚举获取 Key
/// </summary>
/// <param name="e">图标名称枚举</param>
/// <returns>注册到资源中的 Key</returns>
/// <exception cref="NotImplementedException"></exception>
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(),
};
}
/// <summary>
/// 根据图标名称获取 Glyph 枚举
/// </summary>
/// <param name="e">图标名称枚举</param>
/// <returns>图标 Glyph 枚举</returns>
/// <exception cref="NotImplementedException"></exception>
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(),
};
}
/// <summary>
/// 根据图标名称获取 Glyph 字符串
/// </summary>
/// <param name="e">图标名称枚举</param>
/// <returns>图标 Glyph 字符串</returns>
/// <exception cref="NotImplementedException"></exception>
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";
}
}
/// <summary>
/// 图标 Glyph 枚举
/// </summary>
// [TypeConverter(typeof(EnumConverter))]
public enum IconGlyphEnum
{
Empty,
<#
foreach (var entry in glyphToKey)
{
#>
/// <summary>
/// <#= keyToSimpleName[entry.Value] #>
/// <br/>
/// icon-<#= entry.Value #>
/// </summary>
<#= entry.Key #>,
<#
}
#>
}
public static class IconGlyphEnumExtensions
{
/// <summary>
/// 根据 Glyph 枚举获取 Key
/// </summary>
/// <param name="e">Glyph 枚举</param>
/// <returns>注册到资源中的 Key</returns>
/// <exception cref="NotImplementedException"></exception>
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(),
};
}
/// <summary>
/// 根据图标 Glyph 枚举获取图标名称枚举
/// </summary>
/// <param name="e">图标 Glyph 枚举</param>
/// <returns>图标名称枚举</returns>
/// <exception cref="NotImplementedException"></exception>
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(),
};
}
/// <summary>
/// 根据图标 Glyph 枚举获取 Glyph 字符串
/// </summary>
/// <param name="e">图标 Glyph 枚举</param>
/// <returns>图标 Glyph 字符串</returns>
/// <exception cref="NotImplementedException"></exception>
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;
}
}