forked from microsoft/Mobius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleAttribute.cs
58 lines (49 loc) · 1.5 KB
/
SampleAttribute.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Text.RegularExpressions;
namespace Microsoft.Spark.CSharp.Samples
{
/// <summary>
/// Attribute that marks a method as a sample
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
internal class SampleAttribute : Attribute
{
public const string CATEGORY_ALL = "all"; // run all sample tests
public const string CATEGORY_DEFAULT = "default"; // run default tests
private readonly string category;
public SampleAttribute(string category)
{
this.category = category;
}
public SampleAttribute()
{
category = CATEGORY_DEFAULT;
}
public string Category
{
get
{
return category;
}
}
/// <summary>
/// whether this category matches the target category
/// </summary>
// public bool Match(string targetCategory)
public bool Match(Regex targetCategory)
{
if (null == targetCategory)
{
throw new ArgumentNullException("targetCategory");
}
return targetCategory.IsMatch(CATEGORY_ALL)
|| targetCategory.IsMatch(category);
}
public override string ToString()
{
return category;
}
}
}