LinkRelationFactory
Provides string to Relation instance mappings.
using AngleSharp.Dom.Html;
using AngleSharp.Html;
using AngleSharp.Html.LinkRels;
using System;
using System.Collections.Generic;
namespace AngleSharp.Services.Default
{
internal sealed class LinkRelationFactory : ILinkRelationFactory
{
private delegate BaseLinkRelation Creator (HtmlLinkElement link);
private readonly Dictionary<string, Creator> creators = new Dictionary<string, Creator>(StringComparer.OrdinalIgnoreCase) {
{
LinkRelNames.StyleSheet,
(HtmlLinkElement link) => new StyleSheetLinkRelation(link)
},
{
LinkRelNames.Import,
(HtmlLinkElement link) => new ImportLinkRelation(link)
}
};
public BaseLinkRelation Create(HtmlLinkElement link, string rel)
{
Creator value = null;
if (rel != null && creators.TryGetValue(rel, out value))
return value(link);
return null;
}
}
}