DnsFilterListReader Class
Reads DNS filter lists in various formats and produces DnsFilterRule instances. Supports hosts files, domains-only lists, and AdGuard/Adblock DNS filtering syntax.
public static class DnsFilterListReaderRemarks
Parsing is strict: a rule carrying a modifier this library does not implement, or a modifier whose value cannot be parsed, is discarded rather than applied without it. Ignoring an unrecognized modifier would silently widen the rule — turning @@||x^$script into a blanket allow, or ||x^$dnstype=SVCB into a block of every record type. Use DnsFilterListReader.ParseWithDiagnostics to see what was discarded.
Methods
| Name | Description |
|---|---|
| Parse(TextReader, DnsFilterListFormat) | Parses all rules from the specified TextReader. |
| Parse(string, DnsFilterListFormat) | Parses all rules from the specified string. |
| ParseWithDiagnostics(TextReader, DnsFilterListFormat) | Parses a filter list, reporting every line that did not produce a rule. |
| ParseWithDiagnostics(string, DnsFilterListFormat) | Parses a filter list, reporting every line that did not produce a rule. |
Parse overloads
Parse(TextReader, DnsFilterListFormat)
DnsFilterListReader.csParses all rules from the specified TextReader.
public static IReadOnlyList<DnsFilterRule> Parse(TextReader reader, DnsFilterListFormat format = DnsFilterListFormat.AutoDetect)Parameters
readerTextReader- The text reader containing the filter list.
formatDnsFilterListFormat- The format of the filter list. Defaults to
DnsFilterListFormat.AutoDetect.
Returns
IReadOnlyList<DnsFilterRule> A list of parsed filter rules. Lines that could not be parsed are skipped silently; use DnsFilterListReader.ParseWithDiagnostics to observe them.
Parse(string, DnsFilterListFormat)
DnsFilterListReader.csParses all rules from the specified string.
public static IReadOnlyList<DnsFilterRule> Parse(string text, DnsFilterListFormat format = DnsFilterListFormat.AutoDetect)Parameters
textstring- The filter list text.
formatDnsFilterListFormat- The format of the filter list. Defaults to
DnsFilterListFormat.AutoDetect.
Returns
IReadOnlyList<DnsFilterRule> A list of parsed filter rules. Lines that could not be parsed are skipped silently; use DnsFilterListReader.ParseWithDiagnostics to observe them.
ParseWithDiagnostics overloads
ParseWithDiagnostics(TextReader, DnsFilterListFormat)
DnsFilterListReader.csParses a filter list, reporting every line that did not produce a rule.
public static DnsFilterParseResult ParseWithDiagnostics(TextReader reader, DnsFilterListFormat format = DnsFilterListFormat.AutoDetect)Parameters
readerTextReader- The text reader containing the filter list.
formatDnsFilterListFormat- The format of the filter list.
Returns
ParseWithDiagnostics(string, DnsFilterListFormat)
DnsFilterListReader.csParses a filter list, reporting every line that did not produce a rule.
public static DnsFilterParseResult ParseWithDiagnostics(string text, DnsFilterListFormat format = DnsFilterListFormat.AutoDetect)Parameters
textstring- The filter list text.
formatDnsFilterListFormat- The format of the filter list.