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 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Collections
;
36 namespace System
.Web
.UI
{
38 public sealed class CssStyleCollection
41 private StateBag style
;
43 internal CssStyleCollection (StateBag bag
)
46 style
= new StateBag ();
47 string st_string
= bag
["style"] as string;
48 if (st_string
!= null)
49 FillStyle (st_string
);
52 internal void FillStyle (string s
)
54 int mark
= s
.IndexOf (':');
57 string key
= s
.Substring (0, mark
). Trim ();
58 if (mark
+ 1 > s
.Length
)
61 string fullValue
= s
.Substring (mark
+ 1);
65 mark
= fullValue
.IndexOf (';');
68 value = fullValue
.Trim ();
70 value = fullValue
.Substring (0, mark
).Trim ();
72 style
.Add (key
, value);
73 if (mark
+ 1 > fullValue
.Length
)
75 FillStyle (fullValue
.Substring (mark
+ 1));
78 private string BagToString ()
80 StringBuilder sb
= new StringBuilder ();
81 foreach (string k
in style
.Keys
)
82 sb
.AppendFormat ("{0}: {1}; ", k
, style
[k
]);
83 return sb
.ToString ();
88 get { return style.Count; }
91 public string this [string key
]
94 return style
[key
] as string;
102 public ICollection Keys
{
103 get { return style.Keys; }
106 public void Add (string key
, string value)
109 bag
["style"] = BagToString ();
114 bag
.Remove ("style");
118 public void Remove (string key
)
120 if (style
[key
] != null) {
122 bag
["style"] = BagToString ();