/src/NUnit/framework/Attributes/PropertyAttribute.cs
C# | 81 lines | 35 code | 8 blank | 38 comment | 1 complexity | 93ff278d5cfa708d7ddfbe37b8f89242 MD5 | raw file
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 5// **************************************************************** 6 7using System; 8using System.Collections; 9using System.Collections.Specialized; 10 11namespace NUnit.Framework 12{ 13 /// <summary> 14 /// PropertyAttribute is used to attach information to a test as a name/value pair.. 15 /// </summary> 16 [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=true, Inherited=true)] 17 public class PropertyAttribute : Attribute 18 { 19 private IDictionary properties = new ListDictionary(); 20 21 /// <summary> 22 /// Construct a PropertyAttribute with a name and string value 23 /// </summary> 24 /// <param name="propertyName">The name of the property</param> 25 /// <param name="propertyValue">The property value</param> 26 public PropertyAttribute(string propertyName, string propertyValue) 27 { 28 this.properties.Add(propertyName, propertyValue); 29 } 30 31 /// <summary> 32 /// Construct a PropertyAttribute with a name and int value 33 /// </summary> 34 /// <param name="propertyName">The name of the property</param> 35 /// <param name="propertyValue">The property value</param> 36 public PropertyAttribute(string propertyName, int propertyValue) 37 { 38 this.properties.Add(propertyName, propertyValue); 39 } 40 41 /// <summary> 42 /// Construct a PropertyAttribute with a name and double value 43 /// </summary> 44 /// <param name="propertyName">The name of the property</param> 45 /// <param name="propertyValue">The property value</param> 46 public PropertyAttribute(string propertyName, double propertyValue) 47 { 48 this.properties.Add(propertyName, propertyValue); 49 } 50 51 /// <summary> 52 /// Constructor for derived classes that set the 53 /// property dictionary directly. 54 /// </summary> 55 protected PropertyAttribute() { } 56 57 /// <summary> 58 /// Constructor for use by derived classes that use the 59 /// name of the type as the property name. Derived classes 60 /// must ensure that the Type of the property value is 61 /// a standard type supported by the BCL. Any custom 62 /// types will cause a serialization Exception when 63 /// in the client. 64 /// </summary> 65 protected PropertyAttribute( object propertyValue ) 66 { 67 string propertyName = this.GetType().Name; 68 if ( propertyName.EndsWith( "Attribute" ) ) 69 propertyName = propertyName.Substring( 0, propertyName.Length - 9 ); 70 this.properties.Add(propertyName, propertyValue); 71 } 72 73 /// <summary> 74 /// Gets the property dictionary for this attribute 75 /// </summary> 76 public IDictionary Properties 77 { 78 get { return properties; } 79 } 80 } 81}