[add]Add ShowEditorAlias 添加显示编辑器名字

This commit is contained in:
ZensYue
2022-12-02 12:31:15 +08:00
parent 2696da092d
commit aa49980231
10 changed files with 148 additions and 15 deletions
@@ -0,0 +1,55 @@
using System;
using System.Reflection;
namespace YooAsset.Editor
{
/// <summary>
/// 编辑器显示名字
/// </summary>
internal sealed class EditorShowAttribute : Attribute
{
public string Name;
public EditorShowAttribute(string name)
{
this.Name = name;
}
}
internal static class YooAssetAttributes
{
/// <summary>
/// 获取 Type 属性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="type"></param>
/// <returns>可能为空</returns>
internal static T GetAttribute<T>(Type type) where T : Attribute
{
return (T)type.GetCustomAttribute(typeof(T), false);
}
/// <summary>
/// 获取 MethodInfo 属性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="methodInfo"></param>
/// <returns>可能为空</returns>
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
{
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
}
/// <summary>
/// 获取 FieldInfo 属性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="field"></param>
/// <returns>可能为空</returns>
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
{
return (T)field.GetCustomAttribute(typeof(T), false);
}
}
}