Files
DeedyDesigner/DeedyDesigner/Deedy.Activity/Collection/DeedyElementCollection.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2025-09-15 14:07:45 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2025-09-15 15:58:16 +08:00
namespace Deedy.Activity
2025-09-15 14:07:45 +08:00
{
2025-09-16 09:32:07 +08:00
public class DeedyElementCollection : ObservableCollection<IElement>
2025-09-15 14:07:45 +08:00
{
public DeedyElementCollection() : this(false) { }
public DeedyElementCollection(bool needDistinct = false)
{
this._needDistinct = needDistinct;
}
private bool _needDistinct = false;
2025-09-16 09:32:07 +08:00
public void AddRange(params IElement[] elements)
2025-09-15 14:07:45 +08:00
{
foreach (var element in elements) this.Add(element);
}
2025-09-16 09:32:07 +08:00
public void AddRange([AllowNull] IEnumerable<IElement> elements)
2025-09-15 14:07:45 +08:00
{
if (elements != null) foreach (var element in elements) this.Add(element);
}
2025-09-16 09:32:07 +08:00
public new void Add([AllowNull] IElement element)
2025-09-15 14:07:45 +08:00
{
if (element == null) return;
if (this._needDistinct)
{
foreach (var item in this.Items)
{
if (element.DEClass == item.DEClass && element.DETitle == item.DETitle) return;
}
}
base.Add(element);
}
}
}