1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
6 
7 using System;
8 
9 namespace NUnit.Framework
10 {
11 	/// <summary>
12 	/// PropertyAttribute is used to attach information to a test as a name/value pair..
13 	/// </summary>
14 	[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=true)]
15 	public class PropertyAttribute : Attribute
16 	{
17 		/// <summary>
18 		/// The property name
19 		/// </summary>
20 		protected string propertyName;
21 
22 		/// <summary>
23 		/// The property value
24 		/// </summary>
25 		protected object propertyValue;
26 
27 		/// <summary>
28 		/// Construct a PropertyAttribute with a name and value
29 		/// </summary>
30 		/// <param name="propertyName">The name of the property</param>
31 		/// <param name="propertyValue">The property value</param>
PropertyAttribute( string propertyName, object propertyValue )32 		public PropertyAttribute( string propertyName, object propertyValue )
33 		{
34 			this.propertyName = propertyName;
35 			this.propertyValue = propertyValue;
36 		}
37 
38 		/// <summary>
39 		/// Constructor for use by inherited classes that use the
40 		/// name of the type as the property name.
41 		/// </summary>
PropertyAttribute( object propertyValue )42 		protected PropertyAttribute( object propertyValue )
43 		{
44 			this.propertyName = this.GetType().Name;
45 			if ( propertyName.EndsWith( "Attribute" ) )
46 				propertyName = propertyName.Substring( 0, propertyName.Length - 9 );
47 			this.propertyValue = propertyValue;
48 		}
49 
50 		/// <summary>
51 		/// Gets the property name
52 		/// </summary>
53 		public string Name
54 		{
55 			get { return propertyName; }
56 		}
57 
58 		/// <summary>
59 		/// Gets the property value
60 		/// </summary>
61 		public object Value
62 		{
63 			get { return propertyValue; }
64 		}
65 	}
66 }
67