From ff622ee7724b883ea05eff7850d6b1536c99757f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 27 Oct 2025 17:32:49 +0100 Subject: [PATCH] [Foundation] Fix nullability in NSDirectoryEnumerator. This is file 4 of 47 files with nullability disabled in Foundation. Also (by Copilot): * Improve XML documentation and nullability in NSDirectoryEnumerator. * Remove placeholder 'To be added.' comments and replace with proper documentation. * Remove unnecessary whitespace after triple-slash in XML comments. * Add proper attributes for type references. * Add comprehensive documentation for all IEnumerator implementations. * Document exception conditions for Reset and Current properties. Contributes towards https://github.com/dotnet/macios/issues/17285. --- src/Foundation/NSDirectoryEnumerator.cs | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Foundation/NSDirectoryEnumerator.cs b/src/Foundation/NSDirectoryEnumerator.cs index 276d7924673b..3d2d01982101 100644 --- a/src/Foundation/NSDirectoryEnumerator.cs +++ b/src/Foundation/NSDirectoryEnumerator.cs @@ -8,50 +8,50 @@ using System.Collections.Generic; using System.Collections; -// Disable until we get around to enable + fix any issues. -#nullable disable +#nullable enable namespace Foundation { - public partial class NSDirectoryEnumerator : IEnumerator, IEnumerator, IEnumerator { - NSObject current; + public partial class NSDirectoryEnumerator : IEnumerator, IEnumerator, IEnumerator { + NSObject? current; - /// To be added. - /// To be added. - /// To be added. + /// Advances the enumerator to the next element of the collection. + /// if the enumerator was successfully advanced to the next element; if the enumerator has passed the end of the collection. bool IEnumerator.MoveNext () { current = NextObject (); return current is not null; } - /// To be added. - /// To be added. + /// Sets the enumerator to its initial position, which is before the first element in the collection. + /// This operation is not supported for this enumerator. void IEnumerator.Reset () { throw new InvalidOperationException (); } - /// Gets the current element. - /// The current element. - string IEnumerator.Current { + /// Gets the current element as a . + /// The current element as a , or if the enumerator is positioned before the first element or after the last element. + string? IEnumerator.Current { get { - return current.ToString (); + return current?.ToString (); } } - /// Gets the current element. - /// The current element. - NSString IEnumerator.Current { + /// Gets the current element as an . + /// The current element as an , or if the enumerator is positioned before the first element or after the last element, or if the current element is not an . + NSString? IEnumerator.Current { get { return current as NSString; } } - /// Gets the current element. - /// The current element. - /// To be added. + /// Gets the current element in the collection. + /// The current element in the collection. + /// The enumerator is positioned before the first element of the collection or after the last element. object IEnumerator.Current { get { + if (current is null) + throw new InvalidOperationException (); return current; } }