ParseChildrenAttribute.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // System.Web.UI.ParseChildrenAttribute.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com
  9. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Security.Permissions;
  31. namespace System.Web.UI {
  32. // CAS - no InheritanceDemand here as the class is sealed
  33. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  34. // attributes
  35. [AttributeUsage (AttributeTargets.Class)]
  36. public sealed class ParseChildrenAttribute : Attribute
  37. {
  38. bool childrenAsProperties;
  39. string defaultProperty;
  40. public static readonly ParseChildrenAttribute Default = new ParseChildrenAttribute ();
  41. #if NET_2_0
  42. public static readonly ParseChildrenAttribute ParseAsChildren = new ParseChildrenAttribute (false);
  43. public static readonly ParseChildrenAttribute ParseAsProperties = new ParseChildrenAttribute (true);
  44. Type childType = typeof(System.Web.UI.Control);
  45. #endif
  46. // LAMESPEC
  47. public ParseChildrenAttribute ()
  48. {
  49. childrenAsProperties = false;
  50. defaultProperty = "";
  51. }
  52. public ParseChildrenAttribute (bool childrenAsProperties)
  53. {
  54. this.childrenAsProperties = childrenAsProperties;
  55. this.defaultProperty = "";
  56. }
  57. public ParseChildrenAttribute (bool childrenAsProperties,
  58. string defaultProperty)
  59. {
  60. this.childrenAsProperties = childrenAsProperties;
  61. if (childrenAsProperties)
  62. this.defaultProperty = defaultProperty;
  63. }
  64. #if NET_2_0
  65. public ParseChildrenAttribute (Type childControlType)
  66. {
  67. childType = childControlType;
  68. defaultProperty = "";
  69. }
  70. #endif
  71. public bool ChildrenAsProperties {
  72. get { return childrenAsProperties; }
  73. set { childrenAsProperties = value; }
  74. }
  75. public string DefaultProperty {
  76. get { return defaultProperty; }
  77. set { defaultProperty = value; }
  78. }
  79. #if NET_2_0
  80. public Type ChildControlType {
  81. get { return childType; }
  82. }
  83. #endif
  84. public override bool Equals (object obj)
  85. {
  86. ParseChildrenAttribute o = (obj as ParseChildrenAttribute);
  87. if (o == null)
  88. return false;
  89. if (childrenAsProperties == o.childrenAsProperties){
  90. if (childrenAsProperties == false)
  91. return true;
  92. return (defaultProperty == o.DefaultProperty);
  93. }
  94. return false;
  95. }
  96. public override int GetHashCode ()
  97. {
  98. return base.GetHashCode ();
  99. }
  100. public override bool IsDefaultAttribute ()
  101. {
  102. return Equals (Default);
  103. }
  104. }
  105. }