using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace Artemis.Core; /// /// Represents a collection of input pins containing values of type /// /// The type of value the pins in this collection hold public sealed class InputPinCollection : PinCollection { #region Constructors internal InputPinCollection(INode node, string name, int initialCount) : base(node, name) { // Can't do this in the base constructor because the type won't be set yet for (int i = 0; i < initialCount; i++) Add(CreatePin()); } #endregion #region Methods /// public override IPin CreatePin() { return new InputPin(Node, string.Empty); } #endregion #region Properties & Fields /// public override PinDirection Direction => PinDirection.Input; /// public override Type Type => typeof(T); /// /// Gets an enumerable of the pins in this collection /// public new IEnumerable> Pins => base.Pins.Cast>(); /// /// Gets an enumerable of the values of the pins in this collection /// public IEnumerable Values => Pins.Where(p => p.Value != null).Select(p => p.Value!); #endregion } /// /// Represents a collection of input pins /// public sealed class InputPinCollection : PinCollection { private Type _type; #region Constructors internal InputPinCollection(INode node, Type type, string name, int initialCount) : base(node, name) { _type = type; // Can't do this in the base constructor because the type won't be set yet for (int i = 0; i < initialCount; i++) Add(CreatePin()); } #endregion #region Methods /// /// Changes the type of this pin, disconnecting any pins that are incompatible with the new type. /// /// The new type of the pin. public void ChangeType(Type type) { if (_type == type) return; foreach (IPin pin in Pins) (pin as InputPin)?.ChangeType(type); SetAndNotify(ref _type, type, nameof(Type)); } /// public override IPin CreatePin() { return new InputPin(Node, Type, string.Empty); } #endregion #region Properties & Fields /// public override PinDirection Direction => PinDirection.Input; /// public override Type Type => _type; /// /// Gets an enumerable of the values of the pins in this collection /// public IEnumerable Values => Pins.Where(p => p.PinValue != null).Select(p => p.PinValue); #endregion }