Skip to content

Conversation

@rolfbjarne
Copy link
Member

This is file 5 of 30 files with nullability disabled in UIKit.

  • Enable nullability (#nullable enable).
  • Remove unused System.Threading.Tasks using directive.
  • Use ArgumentNullException.ThrowIfNull() instead of manual null checks.
  • Add nullable annotation for Source property (UICollectionViewSource?).
  • Simplify Source property getter with expression body.
  • Replace include file references with inlined XML documentation.
  • Remove inlined DocId entries from docs/api/UIKit/UICollectionView.xml.
  • Improve XML documentation comments: remove 'To be added.' placeholders, fix whitespace, add missing docs, add 'see cref' references.

Contributes towards #17285.

This is file 5 of 30 files with nullability disabled in UIKit.

* Enable nullability (#nullable enable).
* Remove unused System.Threading.Tasks using directive.
* Use ArgumentNullException.ThrowIfNull() instead of manual null checks.
* Add nullable annotation for Source property (UICollectionViewSource?).
* Simplify Source property getter with expression body.
* Replace include file references with inlined XML documentation.
* Remove inlined DocId entries from docs/api/UIKit/UICollectionView.xml.
* Improve XML documentation comments: remove 'To be added.' placeholders, fix whitespace, add missing docs, add 'see cref' references.

Contributes towards #17285.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables nullable reference types for UICollectionView and refreshes related API/documentation to reduce “nullable-disabled” surface area in UIKit.

Changes:

  • Enabled #nullable in src/UIKit/UICollectionView.cs and updated signatures/docs (notably Source and registration helpers).
  • Updated ObjCRuntime.Class.GetHandle to accept nullable Type and return NativeHandle.Zero for null.
  • Removed now-redundant XML DocId blocks from docs/api/UIKit/UICollectionView.xml after inlining docs into source.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/UIKit/UICollectionView.cs Enables nullability and updates helper APIs + XML docs for UICollectionView.
src/ObjCRuntime/Class.cs Adjusts Class.GetHandle nullability/behavior to support nullable call sites.
docs/api/UIKit/UICollectionView.xml Deletes DocId sections that are no longer referenced after doc inlining.

Comment on lines +82 to 84
ArgumentNullException.ThrowIfNull (cellType);

RegisterClassForCell (Class.GetHandle (cellType), reuseIdentifier);
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegisterClassForCell (Type? cellType, NSString reuseIdentifier) declares cellType as nullable and the XML remarks explicitly say callers may pass null to un-register, but the method now throws via ArgumentNullException.ThrowIfNull (cellType). This makes the API contract inconsistent and prevents un-registration. Either allow null by removing the throw (and passing a zero handle), or make cellType non-nullable and update the remarks accordingly.

Suggested change
ArgumentNullException.ThrowIfNull (cellType);
RegisterClassForCell (Class.GetHandle (cellType), reuseIdentifier);
var handle = cellType is null ? System.IntPtr.Zero : Class.GetHandle (cellType);
RegisterClassForCell (handle, reuseIdentifier);

Copilot uses AI. Check for mistakes.
/// <param name="reuseIdentifier">A non-empty string to be associated with the <paramref name="cellType" />.</param>
/// <remarks>
/// <para>The <see cref="UICollectionView" /> maintains a highly-efficient reuse queue for offscreen components. This requires that the <see cref="UICollectionView" /> be responsible for the lifecycle management of its component views. This method (and related methods such as <see cref="RegisterClassForSupplementaryView(Type,UICollectionElementKindSection,string)" />) provide the <see cref="UICollectionView" /> the knowledge of which types it needs to instantiate.</para>
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para>
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remarks say callers may pass null for reuseIdentifier, but reuseIdentifier is non-nullable here; based on the surrounding text this should refer to cellType instead. Please fix the XML documentation so it matches the actual parameters/behavior.

Suggested change
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para>
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="cellType" />, in which case the <paramref name="cellType" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another type, in which case the old type will be "de-registered" and the new <paramref name="cellType" /> will be used.</para>

Copilot uses AI. Check for mistakes.
/// <param name="reuseIdentifier">A non-empty string to be associated with the <paramref name="nib" />.</param>
/// <remarks>
/// <para>The <see cref="UICollectionView" /> maintains a highly-efficient reuse queue for offscreen components. This requires that the <see cref="UICollectionView" /> be responsible for the lifecycle management of its component views. This method (and related methods such as <see cref="RegisterNibForCell(UINib,string)" />) provide the <see cref="UICollectionView" /> the knowledge of which types it needs to instantiate.</para>
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para>
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remarks state callers may pass null for reuseIdentifier, but reuseIdentifier is non-nullable; this appears to mean nib (which is nullable) can be null to un-register. Please correct the XML docs to avoid misleading API consumers.

Suggested change
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="reuseIdentifier" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para>
/// <para>The application developer may pass <see langword="null" /> as the <paramref name="nib" />, in which case the <paramref name="nib" /> will be "un-registered" and no longer instantiated. The application developer may pass in a <paramref name="reuseIdentifier" /> previously associated with another nib, in which case the old nib will be "de-registered" and the new <paramref name="nib" /> will be used.</para>

Copilot uses AI. Check for mistakes.
Comment on lines +201 to +205
public static NativeHandle GetHandle (Type? type)
{
if (type is null)
return NativeHandle.Zero;

Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class.GetHandle now accepts null and returns NativeHandle.Zero for null input, which is a behavioral change (previously null would fail). This can hide programming errors and may have broader impact beyond the intended un-registration scenarios. Consider keeping the existing throwing behavior and introducing a separate helper (or clearly documenting the new null->Zero behavior in the XML docs).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants