-
Notifications
You must be signed in to change notification settings - Fork 95
NameGenerator now honors the RegisterAttribute #482
base: main
Are you sure you want to change the base?
Conversation
Resolves mono#481 by allowing users to override the generated objc class name by decorating their managed class with the RegisterAttribute.
Hello! I'm the build bot for the Mono project. I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Additional trigger words are available here. Contributors can ignore this message. |
whitelist |
Hello! Glad to see you contributing!! I am not entirely sold on reusing 'RegisterAttribute' for this because it could potentially interfere with the Xamarin registrar/runtime. Maybe we'll need embeddinator specific attributes. |
Thanks, old friend! FWIW, I chose to re-use it since the official Xamarin docs state that RegisterAttribute is now used solely to customize the objc class name emitted by the XI generator. Adding a second attribute with the same responsibility would be a DRY violation. If I have a XI assembly using them I'd want it to Just Work. Having two attributes decorating the same class with the same values would be mildly awkward. |
FWIW we also rely on |
Awesome, agree on the intention of reusing it, if @spouliot and @rolfbjarne are ok with this I am too! |
I'm not sure if abusing the First, it means that libraries that want to customize their class names must reference Xamarin.Mac or Xamarin.iOS which is a heavy dependency if you just want to rename a method for use with ObjC. Second, it only works on classes but I'd also like to be able to rename methods and properties. And third: I think a dedicated (thin) E4k support library would make sense for other features too that wouldn't be available in Xamarin.Mac or iOS already. Like a new attribute to tell E4k to not generate bindings for specific classes, methods or properties. |
I'm fine with using @lemonmojo note that this code only does a string comparison for the attribute name; this means that you don't have to reference Xamarin.iOS/Xamarin.Mac, you can define your own |
@rolfbjarne I like it. I'll update the PR. With respect to the other params, like |
@zgramana Just ignore the |
In response to code review feedback, handled RegisterAttribute in the spirit in which StaticRegistrar.cs does in xamarin-macios. Also includes documentation of newly added error codes.
I just pushed a refactor based on @rolfbjarne's feedback for review. |
Actually, hold off for another commit forthcoming. Apologies for the false start. |
The previous refactor ommitted the null check after looking for RegisterAttribute. This commit adds it back in.
Okay, now it's ready for review. In addition to the possible failure modes @rolfbjarne indicated, I also made sure to handle the case of conflicting name values, e.g. |
@zgramana @rolfbjarne Thx for clarifying that there's no external dependency required for this. In this case the PR sounds good to me. I'd still like to be able to also rename specific properties/methods/etc. and exclude certain classes/properties/etc. from being generated but I guess that's fuel for another Issue/PR. |
@zgramana Just noticed a small typo in the updated documentation: |
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.
A few minor comments, and additionally it would be nice to get tests for this as well.
docs/errors.md
Outdated
|
||
If an argument was not also passed for named parameter "Name" then the class will be named according to the default convention. | ||
|
||
<h3><a name="EM1061"/>Invalid `RegisterAttribute` found on class `T`. Expected a constructor with either 1 or 2 parameters but found {argsCount} instead..</h3> |
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.
Typo: two periods at the end of the sentence.
docs/errors.md
Outdated
@@ -217,6 +217,53 @@ Selectors on the [NSObjectProtocol](https://developer.apple.com/reference/object | |||
|
|||
Note: The list of reserved selectors will evolve with new versions of the tool. | |||
|
|||
<h3><a name="EM1060"/>Invalid `RegisterAttribute` found on class `T`. Expected the first constructor parameter to be of type `string` but found type `U` instead.</h3> | |||
|
|||
This is a **warning** that the class `T` was decorated with a `RegisterAttribute`, indicating the author wishes to rename the name of generated objective-c class. |
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.
Minor: use proper casing Objective-C
instead of all lowercase (there are also more cases below).
docs/errors.md
Outdated
|
||
This is a **warning** that the class `T` was decorated with a `RegisterAttribute`, indicating the author wishes to rename the name of generated objective-c class. | ||
|
||
Users already familiar with the `RegisterAttribute` might expect `SkipRegistration` to function is it does in Xamarin.iOS or Xamarin.Android. However, this is unsupported and the value of `SkipRegistration` will be ignored. |
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.
I'm not sure SkipRegistration
is applicable to Xamarin.Android (I don't know anything about XA). Did you mean Xamarin.Mac instead of Xamarin.Android?
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.
Yes, I did, thanks for catching that. My fingers seem to have their own L4 cache…
@rolfbjarne I've pushed up the copy edits you and @lemonmojo found. Unfortunately I'm going to have to leave the tests to someone else as I have to attend to business commitments. Hope this is PR is still helpful. |
Resolves #481 by allowing users to override
the generated objc class name by decorating their managed class
with the RegisterAttribute.