HtmlFormControlsCollection
sealed class HtmlFormControlsCollection : IHtmlFormControlsCollection, IHtmlCollection<IHtmlElement>, IEnumerable<IHtmlElement>, IEnumerable
A specialized collection containing elements of type HTMLFormControlElement.
using AngleSharp.Dom.Html;
using AngleSharp.Extensions;
using AngleSharp.Html;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AngleSharp.Dom.Collections
{
internal sealed class HtmlFormControlsCollection : IHtmlFormControlsCollection, IHtmlCollection<IHtmlElement>, IEnumerable<IHtmlElement>, IEnumerable
{
private readonly IEnumerable<HtmlFormControlElement> _elements;
public int Length => _elements.Count();
public HtmlFormControlElement this[int index] {
get {
return _elements.GetItemByIndex(index);
}
}
public HtmlFormControlElement this[string id] {
get {
return _elements.GetElementById(id);
}
}
IHtmlElement IHtmlCollection<IHtmlElement>.this[int index] {
get {
return this[index];
}
}
IHtmlElement IHtmlCollection<IHtmlElement>.this[string id] {
get {
return this[id];
}
}
public HtmlFormControlsCollection(IElement form, IElement root = null)
{
if (root == null)
root = form.Owner.DocumentElement;
_elements = root.GetElements<HtmlFormControlElement>(true, null).Where(delegate(HtmlFormControlElement m) {
if (m.Form == form) {
IHtmlInputElement htmlInputElement = m as IHtmlInputElement;
if (htmlInputElement == null || !htmlInputElement.Type.Is(InputTypeNames.Image))
return true;
}
return false;
});
}
public IEnumerator<HtmlFormControlElement> GetEnumerator()
{
return _elements.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _elements.GetEnumerator();
}
IEnumerator<IHtmlElement> IEnumerable<IHtmlElement>.GetEnumerator()
{
return _elements.GetEnumerator();
}
}
}