AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="1.0.2-alpha-284" />

 ImportLinkRelation

using AngleSharp.Dom; using AngleSharp.Html.Dom; using AngleSharp.Io; using AngleSharp.Io.Processors; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace AngleSharp.Html.LinkRels { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal class ImportLinkRelation : BaseLinkRelation { private readonly ConditionalWeakTable<IDocument, HashSet<Uri>> ImportLists = new ConditionalWeakTable<IDocument, HashSet<Uri>>(); private bool _async; [System.Runtime.CompilerServices.Nullable(2)] public IDocument Import { [System.Runtime.CompilerServices.NullableContext(2)] get { return (base.Processor as DocumentRequestProcessor)?.ChildDocument; } } public bool IsAsync => _async; public ImportLinkRelation(IHtmlLinkElement link) : base(link, new DocumentRequestProcessor(link?.Owner.Context)) { } public override Task LoadAsync() { IHtmlLinkElement link = base.Link; IDocument owner = link.Owner; Url url = base.Url; IRequestProcessor processor = base.Processor; if (owner != null && url != null && owner.AddImportUrl(url)) { ResourceRequest request = link.CreateRequestFor(url); _async = link.HasAttribute(AttributeNames.Async); return processor?.ProcessAsync(request); } return Task.CompletedTask; } private bool CheckCycle(IDocument document, Url location) { IDocument document2 = document; HashSet<Uri> value; while (document2 != null && ImportLists.TryGetValue(document2, out value)) { if (value.Contains(location)) return true; document2 = document2.ImportAncestor; } return false; } } }