Skip to content

Commit ff622ee

Browse files
committed
[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 <see cref> attributes for type references. * Add comprehensive documentation for all IEnumerator implementations. * Document exception conditions for Reset and Current properties. Contributes towards #17285.
1 parent 298a4dd commit ff622ee

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/Foundation/NSDirectoryEnumerator.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,50 @@
88
using System.Collections.Generic;
99
using System.Collections;
1010

11-
// Disable until we get around to enable + fix any issues.
12-
#nullable disable
11+
#nullable enable
1312

1413
namespace Foundation {
15-
public partial class NSDirectoryEnumerator : IEnumerator<NSString>, IEnumerator<string>, IEnumerator {
16-
NSObject current;
14+
public partial class NSDirectoryEnumerator : IEnumerator<NSString?>, IEnumerator<string?>, IEnumerator {
15+
NSObject? current;
1716

18-
/// <summary>To be added.</summary>
19-
/// <returns>To be added.</returns>
20-
/// <remarks>To be added.</remarks>
17+
/// <summary>Advances the enumerator to the next element of the collection.</summary>
18+
/// <returns><see langword="true"/> if the enumerator was successfully advanced to the next element; <see langword="false"/> if the enumerator has passed the end of the collection.</returns>
2119
bool IEnumerator.MoveNext ()
2220
{
2321
current = NextObject ();
2422
return current is not null;
2523
}
2624

27-
/// <summary>To be added.</summary>
28-
/// <remarks>To be added.</remarks>
25+
/// <summary>Sets the enumerator to its initial position, which is before the first element in the collection.</summary>
26+
/// <exception cref="InvalidOperationException">This operation is not supported for this enumerator.</exception>
2927
void IEnumerator.Reset ()
3028
{
3129
throw new InvalidOperationException ();
3230
}
3331

34-
/// <summary>Gets the current element.</summary>
35-
/// <value>The current element.</value>
36-
string IEnumerator<string>.Current {
32+
/// <summary>Gets the current element as a <see cref="string"/>.</summary>
33+
/// <value>The current element as a <see cref="string"/>, or <see langword="null"/> if the enumerator is positioned before the first element or after the last element.</value>
34+
string? IEnumerator<string?>.Current {
3735
get {
38-
return current.ToString ();
36+
return current?.ToString ();
3937
}
4038
}
4139

42-
/// <summary>Gets the current element.</summary>
43-
/// <value>The current element.</value>
44-
NSString IEnumerator<NSString>.Current {
40+
/// <summary>Gets the current element as an <see cref="NSString"/>.</summary>
41+
/// <value>The current element as an <see cref="NSString"/>, or <see langword="null"/> if the enumerator is positioned before the first element or after the last element, or if the current element is not an <see cref="NSString"/>.</value>
42+
NSString? IEnumerator<NSString?>.Current {
4543
get {
4644
return current as NSString;
4745
}
4846
}
4947

50-
/// <summary>Gets the current element.</summary>
51-
/// <value>The current element.</value>
52-
/// <remarks>To be added.</remarks>
48+
/// <summary>Gets the current element in the collection.</summary>
49+
/// <value>The current element in the collection.</value>
50+
/// <exception cref="InvalidOperationException">The enumerator is positioned before the first element of the collection or after the last element.</exception>
5351
object IEnumerator.Current {
5452
get {
53+
if (current is null)
54+
throw new InvalidOperationException ();
5555
return current;
5656
}
5757
}

0 commit comments

Comments
 (0)