-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathScenarioCategory.cs
More file actions
39 lines (34 loc) · 1.31 KB
/
ScenarioCategory.cs
File metadata and controls
39 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
namespace UICatalog;
/// <summary>Defines the category names used to categorize a <see cref="Scenario"/></summary>
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class ScenarioCategory (string name) : System.Attribute
{
/// <summary>Static helper function to get the <see cref="Scenario"/> Categories given a Type</summary>
/// <param name="t"></param>
/// <returns>list of category names</returns>
public static List<string> GetCategories (Type t)
{
return GetCustomAttributes (t)
.ToList ()
.Where (a => a is ScenarioCategory)
.Select<System.Attribute, string> (a => ((ScenarioCategory)a).Name)
.ToList ();
}
/// <summary>Static helper function to get the <see cref="Scenario"/> Name given a Type</summary>
/// <param name="t"></param>
/// <returns>Name of the category</returns>
public static string GetName (Type t)
{
if (GetCustomAttributes (t).FirstOrDefault (a => a is ScenarioMetadata) is ScenarioMetadata { } metadata)
{
return metadata.Name;
}
return string.Empty;
}
/// <summary>Category Name</summary>
public string Name { get; set; } = name;
}