X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI%2FCssStyleCollection.cs;h=cb2d93e39fa996332878f3c58c63edbed90a84e7;hb=d49951ccf584ba637afb1dab7fff714478e3174d;hp=5ed434ec6ef8445ceba84bcb4473fe5007e2f4cf;hpb=645c832709723d607cd43d410a291273ded7b725;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs b/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs index 5ed434ec6ef..cb2d93e39fa 100644 --- a/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs +++ b/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs @@ -32,6 +32,8 @@ using System.IO; using System.Collections; using System.Security.Permissions; using System.Text; +using System.Collections.Specialized; +using System.Globalization; namespace System.Web.UI { @@ -40,17 +42,25 @@ namespace System.Web.UI { public sealed class CssStyleCollection { StateBag bag; - StateBag style; - string last_string; + HybridDictionary style; internal CssStyleCollection (StateBag bag) { this.bag = bag; - if (bag != null) { - last_string = (string) bag ["style"]; - style = new StateBag (); - if (last_string != null) - FillStyle (last_string); + if (bag != null) + InitFromStyle (); + } + + void InitFromStyle () + { +#if NET_2_0 + style = new HybridDictionary (true); +#else + style = new HybridDictionary (false); +#endif + string att = (string) bag ["style"]; + if (att != null) { + FillStyle (att); } } @@ -82,26 +92,19 @@ namespace System.Web.UI { string BagToString () { - if (last_string != null) - return last_string; - StringBuilder sb = new StringBuilder (); - foreach (string key in Keys) { - if (key == "background-image") + foreach (string key in style.Keys) { + if (key == "background-image" && 0 != String.Compare ("url", ((string) style [key]).Substring (0, 3), true, CultureInfo.InvariantCulture)) sb.AppendFormat ("{0}:url({1});", key, HttpUtility.UrlPathEncode ((string) style [key])); else sb.AppendFormat ("{0}:{1};", key, style [key]); } - last_string = sb.ToString (); - return last_string; + return sb.ToString (); } - public int Count - { + public int Count { get { - if (bag == null) - throw new NullReferenceException (); return style.Count; } } @@ -117,15 +120,14 @@ namespace System.Web.UI { } public ICollection Keys { - get { return style.Keys; } + get { + return style.Keys; + } } public void Add (string key, string value) { - if (style == null) - style = new StateBag (); style [key] = value; - last_string = null; bag ["style"] = BagToString (); } @@ -141,17 +143,15 @@ namespace System.Web.UI { public void Clear () { - if (style != null) - style.Clear (); - last_string = null; + style.Clear (); bag.Remove ("style"); } public void Remove (string key) { - if (style != null) - style.Remove (key); - last_string = null; + if (style [key] == null) + return; + style.Remove (key); bag ["style"] = BagToString (); } #if NET_2_0 @@ -176,13 +176,8 @@ namespace System.Web.UI { string Value { get { return BagToString (); } set { - if (style != null) - style = new StateBag (); - style.Clear (); - last_string = value; bag ["style"] = value; - if (value != null) - FillStyle (value); + InitFromStyle (); } } }