Class LogixContainer<TElement>
- Namespace
- L5Sharp
- Assembly
- L5Sharp.dll
A generic collection that provides operations over an underlying XElement container of LogixElement objects.
public class LogixContainer<TElement> : IEnumerable<TElement>, IEnumerable, ILogixSerializable where TElement : LogixElement
Type Parameters
TElementThe type inheriting LogixElement.
- Inheritance
-
LogixContainer<TElement>
- Implements
-
IEnumerable<TElement>
- Inherited Members
Remarks
This class represents a wrapper around a L5X element that contains a sequence of child elements of the same type. This class exposes collection methods for querying and modifying child elements of the container. Note that a container could potentially contain more than one type of child element, but this container class will only operate over the specified element type.
The class is designed to only offer very basic operations, allowing it to be applicable to all container type elements, However, the user can extended the API for any container type using extension methods and Serialize() to get the underlying XElement container object. See LogixExtensions for examples.
Constructors
LogixContainer()
Creates a empty LogixContainer<TElement> with the default type name.
public LogixContainer()
LogixContainer(IEnumerable<TElement>)
Creates a new LogixContainer<TElement> initialized with the provided collection.
public LogixContainer(IEnumerable<TElement> components)
Parameters
componentsIEnumerable<TElement>The collection of elements to initialize.
LogixContainer(XElement)
Creates a new LogixContainer<TElement> initialized with the provided XElement.
public LogixContainer(XElement container)
Parameters
Exceptions
- ArgumentNullException
containeris null.
LogixContainer(XName)
Creates a empty LogixContainer<TElement> with the specified type name.
public LogixContainer(XName name)
Parameters
nameXNameThe name of the container element.
Properties
this[int]
Accesses a single element at the specified index of the container collection.
public TElement this[int index] { get; set; }
Parameters
indexintThe zero based index of the element to retrieve.
Property Value
- TElement
The element at the specified position in the source container.
Exceptions
- ArgumentOutOfRangeException
indexis less than zero or greater than or equal to the number of elements in the collection.- ArgumentNullException
valueis null when setting index.
Methods
Add(TElement)
Adds the provided element to the logix container at the end of the collection.
public void Add(TElement element)
Parameters
elementTElementThe element to add.
Exceptions
- ArgumentNullException
elementis null.
AddRange(IEnumerable<TElement>)
Adds the provided elements to the logix container at the end of the collection.
public void AddRange(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>The collection of elements to add.
Exceptions
- ArgumentNullException
elementsor any element inelementsis null.
Count()
Gets the number of elements in the collection.
public int Count()
Returns
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<TElement> GetEnumerator()
Returns
- IEnumerator<TElement>
An enumerator that can be used to iterate through the collection.
Insert(int, TElement)
Inserts the provided element at the specified index of the container collection.
public void Insert(int index, TElement element)
Parameters
indexintThe zero based index at which to insert the element.
elementTElementThe element to insert.
Exceptions
- ArgumentNullException
elementis null.- ArgumentOutOfRangeException
indexis less than zero or greater than or equal to the number of elements in the collection.
RemoveAll()
Removes all elements in the container collection.
public void RemoveAll()
RemoveAll(Func<TElement, bool>)
Removes all elements that satisfy the provided condition predicate.
public void RemoveAll(Func<TElement, bool> condition)
Parameters
Exceptions
- ArgumentNullException
conditionis null.
RemoveAt(int)
Removes a element at the specified index of the collection.
public void RemoveAt(int index)
Parameters
indexintThe zero based index of the element to remove.
Exceptions
- ArgumentOutOfRangeException
indexis less than zero or greater than or equal to the number of elements in the collection.
Serialize()
Returns a XElement representing the serialized L5X data for a given object.
public XElement Serialize()
Returns
Update(Action<TElement>)
Updates all elements in the container by applying the provided update action delegate.
public void Update(Action<TElement> update)
Parameters
updateAction<TElement>A update to apply to each element.
Exceptions
- ArgumentNullException
updateis null.
Update(Action<TElement>, Func<TElement, bool>)
Updates all elements in the container that satisfy the provided condition predicate by applying the provided update action delegate.
public void Update(Action<TElement> update, Func<TElement, bool> condition)
Parameters
updateAction<TElement>A update to apply to each element.
conditionFunc<TElement, bool>The condition for which to update elements.
Exceptions
- ArgumentNullException
updateorconditionis null.