1 // ****************************************************************
2 // This is free software licensed under the NUnit license. You
3 // may obtain a copy of the license as well as information regarding
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.
5 // ****************************************************************
6 
7 using System;
8 
9 namespace NUnit.Framework
10 {
11 	/// <summary>
12 	/// Attribute used to apply a category to a test
13 	/// </summary>
14 	[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=true)]
15 	public class CategoryAttribute : Attribute
16 	{
17 		/// <summary>
18 		/// The name of the category
19 		/// </summary>
20 		protected string categoryName;
21 
22 		/// <summary>
23 		/// Construct attribute for a given category
24 		/// </summary>
25 		/// <param name="name">The name of the category</param>
CategoryAttribute(string name)26 		public CategoryAttribute(string name)
27 		{
28 			this.categoryName = name;
29 		}
30 
31 		/// <summary>
32 		/// Protected constructor uses the Type name as the name
33 		/// of the category.
34 		/// </summary>
CategoryAttribute()35 		protected CategoryAttribute()
36 		{
37 			this.categoryName = this.GetType().Name;
38 			if ( categoryName.EndsWith( "Attribute" ) )
39 				categoryName = categoryName.Substring( 0, categoryName.Length - 9 );
40 		}
41 
42 		/// <summary>
43 		/// The name of the category
44 		/// </summary>
45 		public string Name
46 		{
47 			get { return categoryName; }
48 		}
49 	}
50 }
51