AttributeCollection.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. bag.Add (key, value); // if exists, only the value is replaced.
  41. }
  42. public void AddAttributes (HtmlTextWriter writer)
  43. {
  44. foreach (string key in bag.Keys) {
  45. string value = bag [key] as string;
  46. writer.AddAttribute (key, value);
  47. }
  48. }
  49. public void Clear ()
  50. {
  51. bag.Clear ();
  52. }
  53. public void Remove (string key)
  54. {
  55. bag.Remove (key);
  56. }
  57. public void Render (HtmlTextWriter writer)
  58. {
  59. foreach (string key in bag.Keys) {
  60. string value = bag [key] as string;
  61. writer.WriteAttribute (key, value);
  62. }
  63. }
  64. }
  65. }