Commit 38015799 authored by tebjan's avatar tebjan
Browse files

try unboxed checks for attribute changed events

parent f03ac5bd
......@@ -91,9 +91,12 @@ namespace Svg
{
if(base.ContainsKey(attributeName))
{
var oldVal = base[attributeName];
base[attributeName] = value;
if(oldVal != value) OnAttributeChanged(attributeName, value);
var oldVal = base[attributeName];
if(TryUnboxAndCheck(oldVal, value))
{
base[attributeName] = value;
OnAttributeChanged(attributeName, value);
}
}
else
{
......@@ -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>
/// Fired when an Atrribute has changed
/// </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