mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-26 12:08:37 +08:00
69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Specialized;
|
|
// ReSharper disable ArrangeAccessorOwnerBody
|
|
|
|
namespace mRemoteNG.Connection.Protocol
|
|
{
|
|
public class ProtocolList : CollectionBase, INotifyCollectionChanged
|
|
{
|
|
public ProtocolBase this[object index]
|
|
{
|
|
get
|
|
{
|
|
var @base = index as ProtocolBase;
|
|
if (@base != null)
|
|
return @base;
|
|
if (index is int)
|
|
return (ProtocolBase) List[Convert.ToInt32(index)];
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public new int Count
|
|
{
|
|
get { return List.Count; }
|
|
}
|
|
|
|
|
|
public void Add(ProtocolBase cProt)
|
|
{
|
|
List.Add(cProt);
|
|
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, cProt));
|
|
}
|
|
|
|
public void AddRange(ProtocolBase[] cProt)
|
|
{
|
|
foreach (var cP in cProt)
|
|
{
|
|
List.Add(cP);
|
|
}
|
|
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, cProt));
|
|
}
|
|
|
|
public void Remove(ProtocolBase cProt)
|
|
{
|
|
try
|
|
{
|
|
List.Remove(cProt);
|
|
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cProt));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
public new void Clear()
|
|
{
|
|
if (Count == 0) return;
|
|
List.Clear();
|
|
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
}
|
|
|
|
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
|
private void RaiseCollectionChangedEvent(object sender, NotifyCollectionChangedEventArgs args)
|
|
{
|
|
CollectionChanged?.Invoke(sender, args);
|
|
}
|
|
}
|
|
} |