@@ -129,10 +129,10 @@ public class DnsQueryOptions
129129 /// Default is <c>True</c>.
130130 /// </summary>
131131 /// <remarks>
132- /// The query is answered if there is at least one <see cref="DnsResourceRecord"/> in the answers section
132+ /// The query is answered if there is at least one <see cref="DnsResourceRecord"/> in the answers section
133133 /// matching the <see cref="DnsQuestion"/>'s <see cref="QueryType"/>.
134134 /// <para>
135- /// If there are zero answeres in the response, the query is not answered, independent of the <see cref="QueryType"/>.
135+ /// If there are zero answers in the response, the query is not answered, independent of the <see cref="QueryType"/>.
136136 /// If there are answers in the response, the <see cref="QueryType"/> is used to find a matching record,
137137 /// query types <see cref="QueryType.ANY"/> and <see cref="QueryType.AXFR"/> will be ignored by this check.
138138 /// </para>
@@ -241,39 +241,38 @@ public static implicit operator DnsQuerySettings(DnsQueryOptions fromOptions)
241241 /// </summary>
242242 public class DnsQueryAndServerOptions : DnsQueryOptions
243243 {
244- // TODO: evalualte if defaulting resolveNameServers to false here and in the query plan, fall back to configured nameservers of the client
245244 /// <summary>
246245 /// Creates a new instance of <see cref="DnsQueryAndServerOptions"/> without name servers.
247- /// </summary>
248- /// <remarks>
249246 /// If no nameservers are configured, a query will fallback to the nameservers already configured on the <see cref="LookupClient"/> instance.
250- /// </remarks>
251- /// <param name="resolveNameServers">If set to <c>true</c>, <see cref="NameServer.ResolveNameServers(bool, bool)"/>
252- /// will be used to get a list of nameservers.</param>
253- public DnsQueryAndServerOptions ( bool resolveNameServers = false )
254- : this ( resolveNameServers ? NameServer . ResolveNameServers ( ) ? . ToArray ( ) : null )
247+ /// </summary>
248+ public DnsQueryAndServerOptions ( )
255249 {
256- AutoResolvedNameServers = resolveNameServers ;
257250 }
258251
259252 /// <summary>
260253 /// Creates a new instance of <see cref="DnsQueryAndServerOptions"/>.
261254 /// </summary>
262255 /// <param name="nameServers">A collection of name servers.</param>
256+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
263257 public DnsQueryAndServerOptions ( params NameServer [ ] nameServers )
264258 : base ( )
265259 {
266260 if ( nameServers != null && nameServers . Length > 0 )
267261 {
268262 NameServers = nameServers . ToList ( ) ;
269263 }
264+ else
265+ {
266+ throw new ArgumentNullException ( nameof ( nameServers ) ) ;
267+ }
270268 }
271269
272270 // TODO: remove overloads in favor of implicit conversion to NameServer?
273271 /// <summary>
274272 /// Creates a new instance of <see cref="DnsQueryAndServerOptions"/>.
275273 /// </summary>
276274 /// <param name="nameServers">A collection of name servers.</param>
275+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
277276 public DnsQueryAndServerOptions ( params IPEndPoint [ ] nameServers )
278277 : this ( nameServers ? . Select ( p => ( NameServer ) p ) . ToArray ( ) )
279278 {
@@ -283,20 +282,16 @@ public DnsQueryAndServerOptions(params IPEndPoint[] nameServers)
283282 /// Creates a new instance of <see cref="DnsQueryAndServerOptions"/>.
284283 /// </summary>
285284 /// <param name="nameServers">A collection of name servers.</param>
285+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
286286 public DnsQueryAndServerOptions ( params IPAddress [ ] nameServers )
287287 : this ( nameServers ? . Select ( p => ( NameServer ) p ) . ToArray ( ) )
288288 {
289289 }
290290
291291 /// <summary>
292- /// Gets a flag indicating whether the name server collection was manually defined or automatically resolved
293- /// </summary>
294- public bool AutoResolvedNameServers { get ; }
295-
296- /// <summary>
297- /// Gets or sets a list of name servers which should be used to query.
292+ /// Gets a list of name servers which should be used to query.
298293 /// </summary>
299- public IList < NameServer > NameServers { get ; set ; } = new List < NameServer > ( ) ;
294+ public IReadOnlyList < NameServer > NameServers { get ; } = new NameServer [ 0 ] ;
300295
301296 /// <summary>
302297 /// Converts the query options into readonly settings.
@@ -327,40 +322,57 @@ public class LookupClientOptions : DnsQueryAndServerOptions
327322 private TimeSpan ? _maximumCacheTimeout ;
328323
329324 /// <summary>
330- /// Creates a new instance of <see cref="LookupClientOptions"/> without name servers .
325+ /// Creates a new instance of <see cref="LookupClientOptions"/> with default settings .
331326 /// </summary>
332- public LookupClientOptions ( bool resolveNameServers = true )
333- : base ( resolveNameServers )
327+ public LookupClientOptions ( )
328+ : base ( )
334329 {
335330 }
336331
337332 /// <summary>
338333 /// Creates a new instance of <see cref="LookupClientOptions"/>.
339334 /// </summary>
340335 /// <param name="nameServers">A collection of name servers.</param>
336+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
341337 public LookupClientOptions ( params NameServer [ ] nameServers )
342338 : base ( nameServers )
343339 {
340+ AutoResolveNameServers = false ;
344341 }
345342
346343 /// <summary>
347344 /// Creates a new instance of <see cref="LookupClientOptions"/>.
348345 /// </summary>
349346 /// <param name="nameServers">A collection of name servers.</param>
347+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
350348 public LookupClientOptions ( params IPEndPoint [ ] nameServers )
351349 : base ( nameServers )
352350 {
351+ AutoResolveNameServers = false ;
353352 }
354353
355354 /// <summary>
356355 /// Creates a new instance of <see cref="LookupClientOptions"/>.
357356 /// </summary>
358357 /// <param name="nameServers">A collection of name servers.</param>
358+ /// <exception cref="ArgumentNullException">If <paramref name="nameServers"/> is null.</exception>
359359 public LookupClientOptions ( params IPAddress [ ] nameServers )
360360 : base ( nameServers )
361361 {
362+ AutoResolveNameServers = false ;
362363 }
363364
365+ /// <summary>
366+ /// Gets or sets a flag indicating whether the name server collection should be automatically resolved.
367+ /// Default is <c>True</c>.
368+ /// </summary>
369+ /// <remarks>
370+ /// If name servers are configured manually via the constructor, this flag is set to false.
371+ /// If you want both, your manually configured servers and auto resolved name servers,
372+ /// you can use both (ctor or) <see cref="DnsQueryAndServerOptions.NameServers"/> and <see cref="AutoResolveNameServers"/> set to <c>True</c>.
373+ /// </remarks>
374+ public bool AutoResolveNameServers { get ; set ; } = true ;
375+
364376 /// <summary>
365377 /// Gets or sets a <see cref="TimeSpan"/> which can override the TTL of a resource record in case the
366378 /// TTL of the record is lower than this minimum value.
@@ -427,20 +439,6 @@ public TimeSpan? MaximumCacheTimeout
427439 }
428440 }
429441 }
430-
431- /// <summary>
432- /// Converts the options into readonly settings.
433- /// </summary>
434- /// <param name="fromOptions">The options.</param>
435- public static implicit operator LookupClientSettings ( LookupClientOptions fromOptions )
436- {
437- if ( fromOptions == null )
438- {
439- return null ;
440- }
441-
442- return new LookupClientSettings ( fromOptions ) ;
443- }
444442 }
445443
446444#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode() - intentionally, Equals is only used by unit tests
@@ -551,10 +549,10 @@ public class DnsQuerySettings : IEquatable<DnsQuerySettings>
551549 /// Default is <c>True</c>.
552550 /// </summary>
553551 /// <remarks>
554- /// The query is answered if there is at least one <see cref="DnsResourceRecord"/> in the answers section
552+ /// The query is answered if there is at least one <see cref="DnsResourceRecord"/> in the answers section
555553 /// matching the <see cref="DnsQuestion"/>'s <see cref="QueryType"/>.
556554 /// <para>
557- /// If there are zero answeres in the response, the query is not answered, independent of the <see cref="QueryType"/>.
555+ /// If there are zero answers in the response, the query is not answered, independent of the <see cref="QueryType"/>.
558556 /// If there are answers in the response, the <see cref="QueryType"/> is used to find a matching record,
559557 /// query types <see cref="QueryType.ANY"/> and <see cref="QueryType.AXFR"/> will be ignored by this check.
560558 /// </para>
@@ -638,7 +636,7 @@ public DnsQuerySettings(DnsQueryOptions options)
638636 UseTcpFallback = options . UseTcpFallback ;
639637 UseTcpOnly = options . UseTcpOnly ;
640638 ExtendedDnsBufferSize = options . ExtendedDnsBufferSize ;
641- RequestDnsSecRecords = options . RequestDnsSecRecords ;
639+ RequestDnsSecRecords = options . RequestDnsSecRecords ;
642640 }
643641
644642 /// <inheritdocs />
@@ -699,10 +697,6 @@ public class DnsQueryAndServerSettings : DnsQuerySettings, IEquatable<DnsQueryAn
699697 /// </summary>
700698 public IReadOnlyList < NameServer > NameServers => _endpoints ;
701699
702- /// <summary>
703- /// Gets a flag indicating whether the name server collection was manually defined or automatically resolved
704- /// </summary>
705- public bool AutoResolvedNameServers { get ; }
706700
707701 /// <summary>
708702 /// Creates a new instance of <see cref="DnsQueryAndServerSettings"/>.
@@ -711,8 +705,6 @@ public DnsQueryAndServerSettings(DnsQueryAndServerOptions options)
711705 : base ( options )
712706 {
713707 _endpoints = options . NameServers ? . ToArray ( ) ?? new NameServer [ 0 ] ;
714-
715- AutoResolvedNameServers = options . AutoResolvedNameServers ;
716708 }
717709
718710 /// <summary>
@@ -754,7 +746,6 @@ public bool Equals(DnsQueryAndServerSettings other)
754746 }
755747
756748 return NameServers . SequenceEqual ( other . NameServers )
757- && AutoResolvedNameServers == other . AutoResolvedNameServers
758749 && base . Equals ( other ) ;
759750 }
760751
@@ -794,6 +785,13 @@ public LookupClientSettings(LookupClientOptions options)
794785 MaximumCacheTimeout = options . MaximumCacheTimeout ;
795786 }
796787
788+ internal LookupClientSettings ( LookupClientOptions options , IReadOnlyCollection < NameServer > overrideServers )
789+ : base ( options , overrideServers )
790+ {
791+ MinimumCacheTimeout = options . MinimumCacheTimeout ;
792+ MaximumCacheTimeout = options . MaximumCacheTimeout ;
793+ }
794+
797795 /// <summary>
798796 /// Gets a <see cref="TimeSpan"/> which can override the TTL of a resource record in case the
799797 /// TTL of the record is lower than this minimum value.
@@ -870,7 +868,7 @@ internal LookupClientSettings Copy(
870868 bool ? useTcpOnly = null )
871869 {
872870 // auto resolved flag might get lost here. But this stuff gets deleted anyways.
873- return new LookupClientOptions ( nameServers ? . ToArray ( ) )
871+ return new LookupClientSettings ( new LookupClientOptions ( nameServers ? . ToArray ( ) )
874872 {
875873 MinimumCacheTimeout = minimumCacheTimeout ,
876874 ContinueOnDnsError = continueOnDnsError ?? ContinueOnDnsError ,
@@ -887,7 +885,7 @@ internal LookupClientSettings Copy(
887885 ExtendedDnsBufferSize = ExtendedDnsBufferSize ,
888886 RequestDnsSecRecords = RequestDnsSecRecords ,
889887 ContinueOnEmptyResponse = ContinueOnEmptyResponse
890- } ;
888+ } ) ;
891889 }
892890
893891 // TODO: remove if LookupClient settings can be made readonly
0 commit comments