-
Notifications
You must be signed in to change notification settings - Fork 544
Hide Java.Lang.Object members meant only for internal use #4582
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
Comments
Also it could be worth adding the |
Unfortunately they cannot be made I really like your idea to at least hide them from the editor/debugger. I'll look into doing that! I'm going to move this to the Xamarin.Android repo, as the code for |
Fixes: #4582 `Java.Lang.Object` and `Java.Lang.Throwable` contain various `public` and `protected` members that are required by our bindings, such as the `Handle` and `PeerReference` properties. We cannot make them `internal` because our bindings need them, but we can make them "invisible" to users using IDEs by applying the attributes: * [`[EditorBrowsable (EditorBrowsableState.Never)]`][0] * [`[DebuggerBrowsable (DebuggerBrowsableState.Never)]`][1] This will prevent them from showing up in IntelliSense and debugger displays, as they should not be used by users. Note they are still usable if needed, they simply do not show up in IntelliSense. You have to type them out manually. Intellisense for a class deriving JLO before:  After:  [0]: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.editorbrowsableattribute [1]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerbrowsableattribute
Fixes: #4582 `Java.Lang.Object` and `Java.Lang.Throwable` contain various `public` and `protected` members that are required by our bindings, such as the `Handle` and `PeerReference` properties. We cannot make them `internal` because our bindings need them, but we can make them "invisible" to users using IDEs by applying the attributes: * [`[EditorBrowsable (EditorBrowsableState.Never)]`][0] * [`[DebuggerBrowsable (DebuggerBrowsableState.Never)]`][1] This will prevent them from showing up in IntelliSense and debugger displays, as they should not be used by users. Note they are still usable if needed, they simply do not show up in IntelliSense. You have to type them out manually. Intellisense for a class deriving JLO before:  After:  [0]: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.editorbrowsableattribute [1]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerbrowsableattribute
Release status update A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix. Fix included in Xamarin.Android 10.3.99.230. Fix included on Windows in Visual Studio 2019 version 16.7 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview. Fix included on macOS in Visual Studio 2019 for Mac version 8.7 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel. |
Release status update A new Release version of Xamarin.Android has now been published that includes the fix for this item. Fix included in Xamarin.Android SDK version 11.0.0.3. Fix included on Windows in Visual Studio 2019 version 16.7. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/. Fix included on macOS in Visual Studio 2019 for Mac version 8.7. To get the new version that includes the fix, check for the latest updates on the Stable updater channel. |
Hi, I just downloaded the latest VS 16.7 and wanted to look at this fix but I found there's a problem with classes that inherit from |
Good point, I added dotnet/java-interop#688 to address this. |
Fixes: #688 Context: dotnet/android#4582 Context: dotnet/android@3c94f6f Context: dotnet/android#4582 (comment) In dotnet/android#4582 we hid "infrastructural" members like `Java.Lang.Object.ThresholdClass` from the editor and debugger using `[DebuggerBrowsable(DebuggerBrowsableState.Never)]` and `[EditorBrowsable(EditorBrowsableState.Never)]`. However, `generator` output overrides these members, and thus they're *still* visible from the IDE editor and debugger. In order to *fully* hide infrastructural members from the editor and debugger, *every occurrence* of the member must also have `DebuggerBrowsableAttribute` and `EditorBrowsableAttribute`! Update `generator` so that all infrastructural members contain the attributes necessary to hide them from code completion, e.g. [global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] public override global::Java.Interop.JniPeerMembers JniPeerMembers { get { return _members; } } This ensures that the members are in fact hidden from IDEs.
Hi, this is not a very important issue, but something I guess would make a dev's life a bit easier :)
I work with Xamarin.Android so I use mostly objects that are bound from Java libs so they inherit from the
Java.Lang.Object
class. The problem here is that it has a few public members that are intended for internal Java.Interop use only. For instancepublic IntPtr Handle
orpublic JniObjectReference PeerReference
.So I'm wondering whether it'd be possible to hide these members as they're making an unwanted noise in IntelliSense and could also possibly lead to some confusion or errors when mistakenly used. The best would of course be to make them internal or something like that or, if that's not possible, the
EditorBrowsable(EditorBrowsableState.Never)
attribute could be added to remove that noise.The text was updated successfully, but these errors were encountered: