Add style serialization
This commit is contained in:
parent
71e21cfa69
commit
04421a00a5
|
@ -316,15 +316,36 @@ namespace Ooui
|
||||||
set {
|
set {
|
||||||
var safeValue = value ?? "inherit";
|
var safeValue = value ?? "inherit";
|
||||||
lock (properties) {
|
lock (properties) {
|
||||||
Value old;
|
if (value == null) {
|
||||||
if (properties.TryGetValue (propertyName, out old)) {
|
properties.Remove (propertyName);
|
||||||
if (EqualityComparer<Value>.Default.Equals (old, safeValue))
|
}
|
||||||
return;
|
else {
|
||||||
|
Value old;
|
||||||
|
if (properties.TryGetValue (propertyName, out old)) {
|
||||||
|
if (EqualityComparer<Value>.Default.Equals (old, safeValue))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
properties[propertyName] = safeValue;
|
||||||
}
|
}
|
||||||
properties[propertyName] = safeValue;
|
|
||||||
}
|
}
|
||||||
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
|
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 ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,5 +38,37 @@ namespace Tests
|
||||||
s.BackgroundColor = "blue";
|
s.BackgroundColor = "blue";
|
||||||
Assert.AreEqual (2, changeCount);
|
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 ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue