diff --git a/Ooui/Style.cs b/Ooui/Style.cs index 28447da..667f569 100644 --- a/Ooui/Style.cs +++ b/Ooui/Style.cs @@ -316,15 +316,36 @@ namespace Ooui set { var safeValue = value ?? "inherit"; lock (properties) { - Value old; - if (properties.TryGetValue (propertyName, out old)) { - if (EqualityComparer.Default.Equals (old, safeValue)) - return; + if (value == null) { + properties.Remove (propertyName); + } + else { + Value old; + if (properties.TryGetValue (propertyName, out old)) { + if (EqualityComparer.Default.Equals (old, safeValue)) + return; + } + properties[propertyName] = safeValue; } - properties[propertyName] = safeValue; } PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName)); } } + + public override string ToString () + { + var o = new System.Text.StringBuilder (); + var head = ""; + lock (properties) { + foreach (var p in properties) { + o.Append (head); + o.Append (p.Key); + o.Append (":"); + o.Append (String.Format (System.Globalization.CultureInfo.InvariantCulture, "{0}", p.Value)); + head = ";"; + } + } + return o.ToString (); + } } } diff --git a/Tests/StyleTests.cs b/Tests/StyleTests.cs index a6919af..c909ec8 100644 --- a/Tests/StyleTests.cs +++ b/Tests/StyleTests.cs @@ -38,5 +38,37 @@ namespace Tests s.BackgroundColor = "blue"; Assert.AreEqual (2, changeCount); } + + [TestMethod] + public void EmptyString () + { + var s = new Style (); + Assert.AreEqual ("", s.ToString ()); + } + + [TestMethod] + public void SingleString () + { + var s = new Style (); + s.BackgroundColor = "red"; + Assert.AreEqual ("background-color:red", s.ToString ()); + } + + [TestMethod] + public void NullString () + { + var s = new Style (); + s.BackgroundColor = "red"; + s.BackgroundColor = null; + Assert.AreEqual ("", s.ToString ()); + } + + [TestMethod] + public void FloatString () + { + var s = new Style (); + s.BorderLeftWidth = 3.142; + Assert.AreEqual ("border-left-width:3.142", s.ToString ()); + } } }