made svg transform collection a proper ICloneable

This commit is contained in:
tebjan 2014-03-28 12:59:17 +00:00
Родитель cecce65479
Коммит 4d631e7f1a
2 изменённых файлов: 21 добавлений и 9 удалений

Просмотреть файл

@ -676,9 +676,7 @@ namespace Svg
if (this.Transforms != null)
{
newObj.Transforms = new SvgTransformCollection();
foreach (var transform in this.Transforms)
newObj.Transforms.Add(transform.Clone() as SvgTransform);
newObj.Transforms = this.Transforms.Clone() as SvgTransformCollection;
}
foreach (var child in this.Children)

Просмотреть файл

@ -8,12 +8,16 @@ using System.Text;
namespace Svg.Transforms
{
[TypeConverter(typeof(SvgTransformConverter))]
public class SvgTransformCollection : List<SvgTransform>
public class SvgTransformCollection : List<SvgTransform>, ICloneable
{
public new void Add(SvgTransform item)
private void AddItem(SvgTransform item)
{
base.Add(item);
}
public new void Add(SvgTransform item)
{
AddItem(item);
OnTransformChanged();
}
@ -91,9 +95,19 @@ namespace Svg.Transforms
var handler = TransformChanged;
if(handler != null)
{
handler(this, new AttributeEventArgs { Attribute = "transform", Value = this });
//make a copy of the current value to avoid collection changed exceptions
handler(this, new AttributeEventArgs { Attribute = "transform", Value = this.Clone() });
}
}
}
public object Clone()
{
var result = new SvgTransformCollection();
foreach (var trans in this)
{
result.AddItem(trans.Clone() as SvgTransform);
}
return result;
}
}
}