enum.sbn 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {{~
  2. comment = __enum.comment
  3. items = __enum.items
  4. itemType = 'Luban.EditorEnumItemInfo'
  5. ~}}
  6. {{namespace_with_grace_begin __namespace_with_top_module}}
  7. {{~if comment != '' ~}}
  8. /// <summary>
  9. /// {{escape_comment comment}}
  10. /// </summary>
  11. {{~end~}}
  12. {{~if __enum.is_flags~}}
  13. [System.Flags]
  14. {{~end~}}
  15. public enum {{__name}}
  16. {
  17. {{~ for item in items ~}}
  18. {{~if item.comment != '' ~}}
  19. /// <summary>
  20. /// {{escape_comment item.comment_or_alias}}
  21. /// </summary>
  22. {{~end~}}
  23. {{format_enum_item_name __code_style item.name}} = {{item.value}},
  24. {{~end~}}
  25. }
  26. public static class {{__name}}_Metadata
  27. {
  28. {{~ for item in items ~}}
  29. public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");
  30. {{~end~}}
  31. private static readonly System.Collections.Generic.List<{{itemType}}> __items = new System.Collections.Generic.List<{{itemType}}>
  32. {
  33. {{~ for item in items ~}}
  34. {{item.name}},
  35. {{~end~}}
  36. };
  37. public static System.Collections.Generic.List<{{itemType}}> GetItems() => __items;
  38. public static {{itemType}} GetByName(string name)
  39. {
  40. return __items.Find(c => c.Name == name);
  41. }
  42. public static {{itemType}} GetByNameOrAlias(string name)
  43. {
  44. return __items.Find(c => c.Name == name || c.Alias == name);
  45. }
  46. public static {{itemType}} GetByValue(int value)
  47. {
  48. return __items.Find(c => c.Value == value);
  49. }
  50. }
  51. {{namespace_with_grace_end __namespace_with_top_module}}