DisplayNameAttribute.cs 764 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Reflection;
  3. namespace YooAsset.Editor
  4. {
  5. /// <summary>
  6. /// 编辑器显示名字
  7. /// </summary>
  8. public class DisplayNameAttribute : Attribute
  9. {
  10. public string DisplayName;
  11. public DisplayNameAttribute(string name)
  12. {
  13. this.DisplayName = name;
  14. }
  15. }
  16. public static class DisplayNameAttributeHelper
  17. {
  18. internal static T GetAttribute<T>(Type type) where T : Attribute
  19. {
  20. return (T)type.GetCustomAttribute(typeof(T), false);
  21. }
  22. internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
  23. {
  24. return (T)methodInfo.GetCustomAttribute(typeof(T), false);
  25. }
  26. internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
  27. {
  28. return (T)field.GetCustomAttribute(typeof(T), false);
  29. }
  30. }
  31. }