PageRenderTime 24ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/framework/Attributes/PropertyAttribute.cs

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