ScenarioMetadata.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #nullable enable
  2. using System;
  3. using System.Linq;
  4. namespace UICatalog;
  5. /// <summary>Defines the metadata (Name and Description) for a <see cref="Scenario"/></summary>
  6. [AttributeUsage (AttributeTargets.Class)]
  7. public class ScenarioMetadata (string name, string description) : System.Attribute
  8. {
  9. /// <summary><see cref="Scenario"/> Description</summary>
  10. public string Description { get; set; } = description;
  11. /// <summary>Static helper function to get the <see cref="Scenario"/> Description given a Type</summary>
  12. /// <param name="t"></param>
  13. /// <returns></returns>
  14. public static string GetDescription (Type t)
  15. {
  16. if (GetCustomAttributes (t).FirstOrDefault (a => a is ScenarioMetadata) is ScenarioMetadata { } metadata)
  17. {
  18. return metadata.Description;
  19. }
  20. return string.Empty;
  21. }
  22. /// <summary>Static helper function to get the <see cref="Scenario"/> Name given a Type</summary>
  23. /// <param name="t"></param>
  24. /// <returns></returns>
  25. public static string GetName (Type t)
  26. {
  27. if (GetCustomAttributes (t).FirstOrDefault (a => a is ScenarioMetadata) is ScenarioMetadata { } metadata)
  28. {
  29. return metadata.Name;
  30. }
  31. return string.Empty;
  32. }
  33. /// <summary><see cref="Scenario"/> Name</summary>
  34. public string Name { get; set; } = name;
  35. }