2 // System.Web.UI.CssStyleCollection.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua (gonzalo@ximian.com)
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
12 using System.Collections;
15 namespace System.Web.UI {
17 public sealed class CssStyleCollection
20 private StateBag style;
22 internal CssStyleCollection (StateBag bag)
25 style = new StateBag ();
26 string st_string = bag ["style"] as string;
27 if (st_string != null)
28 FillStyle (st_string);
31 internal void FillStyle (string s)
33 int mark = s.IndexOf (':');
36 string key = s.Substring (0, mark). Trim ();
37 if (mark + 1 > s.Length)
40 string fullValue = s.Substring (mark + 1);
44 mark = fullValue.IndexOf (';');
47 value = fullValue.Trim ();
49 value = fullValue.Substring (0, mark).Trim ();
51 style.Add (key, value);
52 if (mark + 1 > fullValue.Length)
54 FillStyle (fullValue.Substring (mark + 1));
57 private string BagToString ()
59 StringBuilder sb = new StringBuilder ();
60 foreach (string k in style.Keys)
61 sb.AppendFormat ("{0}: {1}; ", k, style [k]);
62 return sb.ToString ();
67 get { return style.Count; }
70 public string this [string key]
73 return style [key] as string;
81 public ICollection Keys {
82 get { return style.Keys; }
85 public void Add (string key, string value)
88 bag ["style"] = BagToString ();
97 public void Remove (string key)
99 if (style [key] != null) {
101 bag ["style"] = BagToString ();