Commit 38015799 authored by tebjan's avatar tebjan
Browse files

try unboxed checks for attribute changed events

parent f03ac5bd
...@@ -92,8 +92,11 @@ namespace Svg ...@@ -92,8 +92,11 @@ namespace Svg
if(base.ContainsKey(attributeName)) if(base.ContainsKey(attributeName))
{ {
var oldVal = base[attributeName]; var oldVal = base[attributeName];
if(TryUnboxAndCheck(oldVal, value))
{
base[attributeName] = value; base[attributeName] = value;
if(oldVal != value) OnAttributeChanged(attributeName, value); OnAttributeChanged(attributeName, value);
}
} }
else else
{ {
...@@ -103,6 +106,40 @@ namespace Svg ...@@ -103,6 +106,40 @@ namespace Svg
} }
} }
private bool TryUnboxAndCheck(object a, object b)
{
System.Diagnostics.Debug.WriteLine("object type: " + a.GetType().ToString());
if(IsValueType(a))
{
System.Diagnostics.Debug.WriteLine("is value type");
if(a is SvgUnit)
return UnboxAndCheck<SvgUnit>(a, b);
else if(a is bool)
return UnboxAndCheck<bool>(a, b);
else if(a is int)
return UnboxAndCheck<int>(a, b);
else if(a is float)
return UnboxAndCheck<float>(a, b);
else
return true;
}
else
{
return a != b;
}
}
private bool UnboxAndCheck<T>(object a, object b)
{
return !((T)a).Equals((T)b);
}
private bool IsValueType(object obj)
{
return obj != null && obj.GetType().IsValueType;
}
/// <summary> /// <summary>
/// Fired when an Atrribute has changed /// Fired when an Atrribute has changed
/// </summary> /// </summary>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment