Skip to content

[RGen] Update the BindingAttribute to allow to pass the type for a category. #23358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2025

Conversation

mandel-macaque
Copy link
Member

@mandel-macaque mandel-macaque commented Jul 18, 2025

This allows to pass the type rather than the name of the type which is a safer approach since the compiler will help us. The creation of a Category will now look like:

[Binding<Category>(typeof (NSObject))]
public static class MyCategory {
  // static extension methods
}

…tegory.

This allows to pass the type rather than the name of the type which is a
safer approach since the compiler will help us. The creation of a
Category will now look like:

```csharp
[Bindin<Category>(typeof (NSObject))]
public static class MyCategory {
  // static extension methods
}
```
@mandel-macaque mandel-macaque requested a review from Copilot July 18, 2025 22:31
Copy link
Contributor

@Copilot 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 enhances the BindingAttribute to support passing types directly for category definitions rather than just string names, providing compile-time type safety. The key improvement allows developers to use [Binding<Category>(typeof(NSObject))] instead of string-based category definitions.

  • Adds support for Type parameters in BindingTypeAttribute constructors for categories
  • Updates BindingTypeData to handle TypeInfo objects for category type information
  • Modifies parsing logic to differentiate between category and class binding scenarios

Reviewed Changes

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

File Description
src/ObjCBindings/BindingTypeAttribute.cs Adds CategoryType property and new constructors accepting Type parameters
src/rgen/Microsoft.Macios.Generator/Attributes/BindingTypeData.cs Implements CategoryType support with TypeInfo, updates parsing logic, and adds comprehensive documentation
tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingInfoTests.cs Updates test expectations to include CategoryType field in string representations

@@ -266,11 +435,23 @@ public override int GetHashCode ()
return HashCode.Combine (Name, Flags);
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

The GetHashCode method does not include CategoryType in the hash calculation, but CategoryType is used in the Equals method. This violates the contract that objects that are equal must have the same hash code.

Suggested change
return HashCode.Combine (Name, Flags);
return HashCode.Combine (Name, Flags, CategoryType);

Copilot uses AI. Check for mistakes.

@@ -220,26 +372,41 @@ public static bool TryParse (AttributeData attributeData,
stringCtorVisibility = (MethodAttributes) Convert.ToSingle ((int) value.Value!);
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

Using Convert.ToSingle to cast to MethodAttributes is incorrect. This should be a direct cast: (MethodAttributes)(int)value.Value! since MethodAttributes is an enum with int underlying type.

Copilot uses AI. Check for mistakes.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #42b58d6] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #42b58d6] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

✅ API diff vs stable

.NET ( No breaking changes )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #42b58d6] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #42b58d6] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #42b58d6] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #42b58d6] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #42b58d6] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #42b58d6] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 1 tests failed, 125 tests passed.

Failures

❌ monotouch tests (macOS)

1 tests failed, 11 tests passed.
  • monotouch-test/macOS/Debug (static registrar, ARM64): TimedOut (Execution timed out after 1200 seconds.
    Test run crashed)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 10 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 42b58d6fd465adcd4c981bf5c2cd454774608ac9 [PR build]

@mandel-macaque
Copy link
Member Author

Failing tests are unrelated to code changes.

@mandel-macaque mandel-macaque merged commit 73f184e into main Jul 21, 2025
42 of 44 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/binding-attr-category-type branch July 21, 2025 12:18
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.

3 participants