AttributeCollection.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // System.Web.UI.AttributeCollection.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. //
  10. using System;
  11. using System.Collections;
  12. namespace System.Web.UI {
  13. public sealed class AttributeCollection
  14. {
  15. private StateBag bag;
  16. private CssStyleCollection styleCollection;
  17. public AttributeCollection (StateBag bag)
  18. {
  19. this.bag = bag;
  20. }
  21. public int Count {
  22. get { return bag.Count; }
  23. }
  24. public CssStyleCollection CssStyle {
  25. get {
  26. if (styleCollection == null)
  27. styleCollection = new CssStyleCollection (bag);
  28. return styleCollection;
  29. }
  30. }
  31. public string this [string key] {
  32. get { return bag [key] as string; }
  33. set { bag.Add (key, value); }
  34. }
  35. public ICollection Keys {
  36. get { return bag.Keys; }
  37. }
  38. public void Add (string key, string value)
  39. {
  40. if (styleCollection != null && 0 == String.Compare (key, "style", true))
  41. styleCollection.FillStyle (value);
  42. else
  43. bag.Add (key, value);
  44. }
  45. public void AddAttributes (HtmlTextWriter writer)
  46. {
  47. foreach (string key in bag.Keys) {
  48. string value = bag [key] as string;
  49. writer.AddAttribute (key, value);
  50. }
  51. }
  52. public void Clear ()
  53. {
  54. bag.Clear ();
  55. }
  56. public void Remove (string key)
  57. {
  58. bag.Remove (key);
  59. }
  60. public void Render (HtmlTextWriter writer)
  61. {
  62. foreach (string key in bag.Keys) {
  63. string value = bag [key] as string;
  64. writer.WriteAttribute (key, value);
  65. }
  66. }
  67. }
  68. }