AmbientValueAttribute.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // System.ComponentModel.AmbientValueAttribute
  3. //
  4. // Authors:
  5. // Martin Willemoes Hansen ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) 2003 Martin Willemoes Hansen
  9. // (C) 2003 Andreas Nahr
  10. //
  11. namespace System.ComponentModel
  12. {
  13. [AttributeUsage(AttributeTargets.All)]
  14. public sealed class AmbientValueAttribute : Attribute
  15. {
  16. private object AmbientValue;
  17. public AmbientValueAttribute (bool value)
  18. {
  19. AmbientValue = value;
  20. }
  21. public AmbientValueAttribute (byte value)
  22. {
  23. AmbientValue = value;
  24. }
  25. public AmbientValueAttribute (char value)
  26. {
  27. AmbientValue = value;
  28. }
  29. public AmbientValueAttribute (double value)
  30. {
  31. AmbientValue = value;
  32. }
  33. public AmbientValueAttribute (short value)
  34. {
  35. AmbientValue = value;
  36. }
  37. public AmbientValueAttribute (int value)
  38. {
  39. AmbientValue = value;
  40. }
  41. public AmbientValueAttribute (long value)
  42. {
  43. AmbientValue = value;
  44. }
  45. public AmbientValueAttribute (object value)
  46. {
  47. AmbientValue = value;
  48. }
  49. public AmbientValueAttribute (float value)
  50. {
  51. AmbientValue = value;
  52. }
  53. public AmbientValueAttribute (string value)
  54. {
  55. AmbientValue = value;
  56. }
  57. [MonoTODO]
  58. public AmbientValueAttribute (Type type, string value)
  59. {
  60. try {
  61. AmbientValue = Convert.ChangeType (value, type);
  62. } catch {
  63. AmbientValue = null;
  64. }
  65. }
  66. public object Value {
  67. get { return AmbientValue; }
  68. }
  69. public override bool Equals (object obj)
  70. {
  71. if (!(obj is AmbientValueAttribute))
  72. return false;
  73. if (obj == this)
  74. return true;
  75. return ((AmbientValueAttribute) obj).Value == AmbientValue;
  76. }
  77. public override int GetHashCode()
  78. {
  79. return AmbientValue.GetHashCode ();
  80. }
  81. }
  82. }