AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.10" />

.NET API 1,230,336 bytes

 HtmlLinkElement

Represents the HTML link element.
using AngleSharp.Dom.Collections; using AngleSharp.Dom.Css; using AngleSharp.Dom.Events; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Html.LinkRels; using AngleSharp.Network; using AngleSharp.Services; using System.Threading.Tasks; namespace AngleSharp.Dom.Html { internal sealed class HtmlLinkElement : HtmlElement, IHtmlLinkElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IGlobalEventHandlers, ILinkStyle, ILinkImport, ILoadableElement { private BaseLinkRelation _relation; private TokenList _relList; private SettableTokenList _sizes; internal bool IsVisited { get; set; } internal bool IsActive { get; set; } public IDownload CurrentDownload => _relation?.Processor?.Download; public string Href { get { return this.GetUrlAttribute(AttributeNames.Href); } set { this.SetOwnAttribute(AttributeNames.Href, value, false); } } public string TargetLanguage { get { return this.GetOwnAttribute(AttributeNames.HrefLang); } set { this.SetOwnAttribute(AttributeNames.HrefLang, value, false); } } public string Charset { get { return this.GetOwnAttribute(AttributeNames.Charset); } set { this.SetOwnAttribute(AttributeNames.Charset, value, false); } } public string Relation { get { return this.GetOwnAttribute(AttributeNames.Rel); } set { this.SetOwnAttribute(AttributeNames.Rel, value, false); } } public ITokenList RelationList { get { if (_relList == null) { _relList = new TokenList(this.GetOwnAttribute(AttributeNames.Rel)); _relList.Changed += delegate(string value) { UpdateAttribute(AttributeNames.Rel, value); }; } return _relList; } } public ISettableTokenList Sizes { get { if (_sizes == null) { _sizes = new SettableTokenList(this.GetOwnAttribute(AttributeNames.Sizes)); _sizes.Changed += delegate(string value) { UpdateAttribute(AttributeNames.Sizes, value); }; } return _sizes; } } public string Rev { get { return this.GetOwnAttribute(AttributeNames.Rev); } set { this.SetOwnAttribute(AttributeNames.Rev, value, false); } } public bool IsDisabled { get { return this.GetBoolAttribute(AttributeNames.Disabled); } set { this.SetBoolAttribute(AttributeNames.Disabled, value); } } public string Target { get { return this.GetOwnAttribute(AttributeNames.Target); } set { this.SetOwnAttribute(AttributeNames.Target, value, false); } } public string Media { get { return this.GetOwnAttribute(AttributeNames.Media); } set { this.SetOwnAttribute(AttributeNames.Media, value, false); } } public string Type { get { return this.GetOwnAttribute(AttributeNames.Type); } set { this.SetOwnAttribute(AttributeNames.Type, value, false); } } public string Integrity { get { return this.GetOwnAttribute(AttributeNames.Integrity); } set { this.SetOwnAttribute(AttributeNames.Integrity, value, false); } } public IStyleSheet Sheet => (_relation as StyleSheetLinkRelation)?.Sheet; public IDocument Import => (_relation as ImportLinkRelation)?.Import; public string CrossOrigin { get { return this.GetOwnAttribute(AttributeNames.CrossOrigin); } set { this.SetOwnAttribute(AttributeNames.CrossOrigin, value, false); } } public HtmlLinkElement(Document owner, string prefix = null) : base(owner, TagNames.Link, prefix, NodeFlags.SelfClosing | NodeFlags.Special) { } internal override void SetupElement() { base.SetupElement(); string ownAttribute = this.GetOwnAttribute(AttributeNames.Rel); if (ownAttribute != null) UpdateRelation(ownAttribute); } internal void UpdateSizes(string value) { _sizes?.Update(value); } internal void UpdateMedia(string value) { IStyleSheet sheet = Sheet; if (sheet != null) sheet.Media.MediaText = value; } internal void UpdateDisabled(string value) { IStyleSheet sheet = Sheet; if (sheet != null) sheet.IsDisabled = (value != null); } internal void UpdateRelation(string value) { _relList?.Update(value); _relation = CreateFirstLegalRelation(); UpdateSource(this.GetOwnAttribute(AttributeNames.Href)); } internal void UpdateSource(string value) { Task task = _relation?.LoadAsync(); base.Owner?.DelayLoad(task); } private BaseLinkRelation CreateFirstLegalRelation() { ITokenList relationList = RelationList; Document owner = base.Owner; ILinkRelationFactory linkRelationFactory = (owner != null) ? owner.Options.GetFactory<ILinkRelationFactory>() : null; foreach (string item in relationList) { BaseLinkRelation baseLinkRelation = linkRelationFactory.Create(this, item); if (baseLinkRelation != null) return baseLinkRelation; } return null; } } }