2
0

AttributeCollection.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // System.Web.UI.AttributeCollection.cs
  3. //
  4. // Duncan Mak ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. //
  8. using System;
  9. using System.Collections;
  10. namespace System.Web.UI {
  11. public sealed class AttributeCollection
  12. {
  13. private StateBag bag;
  14. public AttributeCollection (StateBag bag)
  15. {
  16. this.bag = bag;
  17. }
  18. public int Count {
  19. get { return bag.Count; }
  20. }
  21. [MonoTODO]
  22. public CssStyleCollection CssStyle {
  23. get { return null; }
  24. }
  25. public string this [string key] {
  26. get { return bag [key] as string; }
  27. set { bag.Add (key, value); }
  28. }
  29. public ICollection Keys {
  30. get { return bag.Keys; }
  31. }
  32. public void Add (string key, string value)
  33. {
  34. bag.Add (key, value); // if exists, only the value is replaced.
  35. }
  36. public void AddAttributes (HtmlTextWriter writer)
  37. {
  38. foreach (string key in bag.Keys) {
  39. string value = bag [key] as string;
  40. writer.AddAttribute (key, value);
  41. }
  42. }
  43. public void Clear ()
  44. {
  45. bag.Clear ();
  46. }
  47. public void Remove (string key)
  48. {
  49. bag.Remove (key);
  50. }
  51. public void Render (HtmlTextWriter writer)
  52. {
  53. foreach (string key in bag.Keys) {
  54. string value = bag [key] as string;
  55. writer.WriteAttribute (key, value);
  56. }
  57. }
  58. }
  59. }