Files
DeedyDesigner/DeedyDesigner/Deedy.Activity/Collection/DeedyElementCollection.cs
2025-09-15 16:02:53 +08:00

41 lines
1.3 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<IDeedyElement>
{
public DeedyElementCollection() : this(false) { }
public DeedyElementCollection(bool needDistinct = false)
{
this._needDistinct = needDistinct;
}
private bool _needDistinct = false;
public void AddRange(params IDeedyElement[] elements)
{
foreach (var element in elements) this.Add(element);
}
public void AddRange([AllowNull] IEnumerable<IDeedyElement> elements)
{
if (elements != null) foreach (var element in elements) this.Add(element);
}
public new void Add([AllowNull] IDeedyElement 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);
}
}
}