-
Notifications
You must be signed in to change notification settings - Fork 543
[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
Conversation
…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 } ```
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
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!); |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #42b58d6] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #42b58d6] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commit.NET ( No breaking changes )✅ API diff vs stable.NET ( No breaking changes )ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #42b58d6] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #42b58d6] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #42b58d6] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #42b58d6] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #42b58d6] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
🔥 [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)
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Failing tests are unrelated to code changes. |
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: