Files
DeedyDesigner/DeedyDesigner/Deedy.Activity/Collection/DeedyElementCollection.cs
2025-09-16 09:32:07 +08:00

41 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Activity
{
public class DeedyElementCollection : ObservableCollection<IElement>
{
public DeedyElementCollection() : this(false) { }
public DeedyElementCollection(bool needDistinct = false)
{
this._needDistinct = needDistinct;
}
private bool _needDistinct = false;
public void AddRange(params IElement[] elements)
{
foreach (var element in elements) this.Add(element);
}
public void AddRange([AllowNull] IEnumerable<IElement> elements)
{
if (elements != null) foreach (var element in elements) this.Add(element);
}
public new void Add([AllowNull] IElement element)
{
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);
}
}
}