Skip to content

Conversation

@Sergio0694
Copy link
Member

Title.

Examples of codegen:

image

Note

Draft because there's some commits to move and this branch also needs to be rebased.

Moved the SetAt method logic for IList<T> to InteropMethodDefinitionFactory.IVectorMethods, replacing the previous placeholder implementation. This centralizes method creation and provides a complete method body for SetAt, improving maintainability and consistency.
Introduces a shared SetAtOrInsertAt helper to generate both SetAt and InsertAt methods for IVector<T> interfaces, reducing code duplication and improving maintainability. Updates method body construction to use the new helper and parameterize method name and signature.
Moves InsertAt method definition logic from InteropTypeDefinitionBuilder.IList1 to InteropMethodDefinitionFactory.IVectorMethods. This centralizes method creation and reduces duplication, improving maintainability.
Moved the construction of the IList<T>.Append method to InteropMethodDefinitionFactory.IVectorMethods.Append, providing a full method body and parameter marshaling logic. This improves maintainability and consistency with other interop method definitions.
Refactored IList<T> interop builder to use a new InteropMethodDefinitionFactory.IVectorMethods.IndexOf method, which now provides a full implementation for the IndexOf method, including method body and parameter marshaling. This improves maintainability and consistency with other IVector methods.
Updated the XML documentation for CilOutParameterIndices to clarify that parameter indices are 1-based, with index 0 representing the implicit 'this' parameter.
Copy link

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

This PR implements full code generation for IVectorMethods types in the cswinrtgen tool. Previously, these methods had placeholder implementations that threw exceptions; now they generate complete CIL method bodies with proper marshalling, exception handling, and resource cleanup.

Key changes:

  • Adds factory methods for generating SetAt, InsertAt, Append, and IndexOf implementations
  • Implements proper try/finally blocks for resource cleanup
  • Handles parameter marshalling with native type conversion

Reviewed changes

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

File Description
InteropMethodDefinitionFactory.IVectorMethods.cs New file containing factory methods for generating complete IVector<T> method implementations with CIL bodies
MethodDefinitionExtensions.cs Added documentation clarifying that CilOutParameterIndices uses 1-based indexing
InteropTypeDefinitionBuilder.IList1.cs Replaced placeholder method stubs with calls to the new factory methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Track rewriting the 'value' parameter for this method
emitState.TrackNativeParameterMethodRewrite(
paraneterType: elementType,
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'paraneterType' to 'parameterType'.

Suggested change
paraneterType: elementType,
parameterType: elementType,

Copilot uses AI. Check for mistakes.

// Track rewriting the 'value' parameter for this method
emitState.TrackNativeParameterMethodRewrite(
paraneterType: elementType,
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'paraneterType' to 'parameterType'.

Suggested change
paraneterType: elementType,
parameterType: elementType,

Copilot uses AI. Check for mistakes.

// Track rewriting the 'value' parameter for this method
emitState.TrackNativeParameterMethodRewrite(
paraneterType: elementType,
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'paraneterType' to 'parameterType'.

Suggested change
paraneterType: elementType,
parameterType: elementType,

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