DnsFilterRule Class

Represents a single parsed DNS filter rule.

public sealed class DnsFilterRule

Properties

NameDescription
ActionGets the action to perform when this rule matches. Always DnsFilterAction.Block or DnsFilterAction.Allow.
AllowedDnsTypesGets the set of DNS query types this rule applies to (from $dnstype modifier). null means the rule applies to all query types.
DenyAllowDomainsGets the set of domains excluded from this rule (from $denyallow modifier).
DomainSuffixGets the domain suffix this rule matches (for ||domain^ style rules that match the domain and all its subdomains), or null.
ExactDomainGets the exact domain this rule matches, or null if it does not match by exact domain.
ExcludedDnsTypesGets the set of DNS query types this rule does not apply to (from $dnstype=~ modifier). null means no types are excluded.
IsBadFilterGets a value indicating whether this is a $badfilter rule that disables another rule matching its pattern and modifiers.
IsImportantGets a value indicating whether this rule has the $important modifier, which elevates its priority above normal rules and exceptions.
OriginalTextGets the original text of the rule as it appeared in the filter list.
PatternTextGets the regular expression source this rule matches with, or null. Set for /regex/ rules and for patterns containing *.
RewriteGets the rewrite directive for this rule (from $dnsrewrite modifier).

Gets the action to perform when this rule matches. Always DnsFilterAction.Block or DnsFilterAction.Allow.

public required DnsFilterAction Action { get; init; }

Property value

DnsFilterAction

AllowedDnsTypes

DnsFilterRule.cs

Gets the set of DNS query types this rule applies to (from $dnstype modifier). null means the rule applies to all query types.

public IReadOnlyCollection<DnsFilterQueryType>? AllowedDnsTypes { get; init; }

DenyAllowDomains

DnsFilterRule.cs

Gets the set of domains excluded from this rule (from $denyallow modifier).

public IReadOnlyCollection<string>? DenyAllowDomains { get; init; }

DomainSuffix

DnsFilterRule.cs

Gets the domain suffix this rule matches (for ||domain^ style rules that match the domain and all its subdomains), or null.

public string? DomainSuffix { get; init; }

Property value

string?

ExactDomain

DnsFilterRule.cs

Gets the exact domain this rule matches, or null if it does not match by exact domain.

public string? ExactDomain { get; init; }

Property value

string?

ExcludedDnsTypes

DnsFilterRule.cs

Gets the set of DNS query types this rule does not apply to (from $dnstype=~ modifier). null means no types are excluded.

public IReadOnlyCollection<DnsFilterQueryType>? ExcludedDnsTypes { get; init; }

IsBadFilter

DnsFilterRule.cs

Gets a value indicating whether this is a $badfilter rule that disables another rule matching its pattern and modifiers.

public bool IsBadFilter { get; init; }

Property value

bool

IsImportant

DnsFilterRule.cs

Gets a value indicating whether this rule has the $important modifier, which elevates its priority above normal rules and exceptions.

public bool IsImportant { get; init; }

Property value

bool

OriginalText

DnsFilterRule.cs

Gets the original text of the rule as it appeared in the filter list.

public required string OriginalText { get; init; }

Property value

string

Remarks

This is provided for diagnostics only. It is not the rule's identity: use DnsFilterRule.ExactDomain, DnsFilterRule.DomainSuffix or DnsFilterRule.PatternText to report what the rule actually matches.

PatternText

DnsFilterRule.cs

Gets the regular expression source this rule matches with, or null. Set for /regex/ rules and for patterns containing *.

public string? PatternText { get; }

Property value

string?

Gets the rewrite directive for this rule (from $dnsrewrite modifier).

public DnsFilterRewriteRule? Rewrite { get; init; }

Property value

DnsFilterRewriteRule?

Methods

NameDescription
CreateAllow(string, bool)Creates an exception rule allowing a single domain, and optionally all of its subdomains.
CreateBlock(string, bool)Creates a rule blocking a single domain, and optionally all of its subdomains.

CreateAllow(string, bool)

DnsFilterRule.cs

Creates an exception rule allowing a single domain, and optionally all of its subdomains.

public static DnsFilterRule CreateAllow(string domain, bool includeSubdomains = false)

Parameters

domain string
The domain to allow.
includeSubdomains bool
When true, subdomains are allowed too.

Returns

DnsFilterRule

Exceptions

ArgumentException
domain is not a valid domain name.

CreateBlock(string, bool)

DnsFilterRule.cs

Creates a rule blocking a single domain, and optionally all of its subdomains.

public static DnsFilterRule CreateBlock(string domain, bool includeSubdomains = false)

Parameters

domain string
The domain to block.
includeSubdomains bool
When true, subdomains are blocked too.

Returns

DnsFilterRule

Exceptions

ArgumentException
domain is not a valid domain name.