Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 12, 2024

Fixes: #802

For interfaces that contain static consts or other members that traditionally could not be placed in a C# interface we create an abstract class with an internal constructor that contains the members so users could access them. However, we place a [Register] on them that points to the original interface. This can cause problems when trying to resolve Java -> C# types, as multiple C# types [Register] the same Java type:

[Register ("android/provider/BaseColumns", DoNotGenerateAcw=true)] 
public abstract class BaseColumns : Java.Lang.Object { ... }

[Register ("android/provider/BaseColumns", DoNotGenerateAcw=true)] 
public abstract class BaseColumnsConsts : IBaseColumns { ... }

[Register ("android/provider/BaseColumns", "", "android.provider.IBaseColumnsInvoker")] 
public interface IBaseColumns { ... }

We tried to remove these [Register] attributes by default, but then JCWs would get generated for them as they inherit JLO and no longer had DoNotGenerateAcw. Instead, we will place them in a dummy package (mono/internal/etc) so that any user that finds them will get a hint that they are "internal" details. (Note that we will never actually generate the JCW files because of DoNotGenerateAcw.)

[Register ("mono/internal/android/provider/BaseColumns", DoNotGenerateAcw=true)] 
public abstract class BaseColumns : Java.Lang.Object { ... }

[Register ("mono/internal/android/provider/BaseColumns", DoNotGenerateAcw=true)] 
public abstract class BaseColumnsConsts : IBaseColumns { ... }

dotnet/android test PR: dotnet/android#9196

@jpobst jpobst force-pushed the register-alternatives branch from 0322976 to 01fa29a Compare August 14, 2024 21:42
@jpobst jpobst changed the title [generator] Do not [Register] interface alternatives by default. [generator] Place interface alternatives [Register] classes in dummy package. Aug 15, 2024
@jpobst jpobst force-pushed the register-alternatives branch from 01fa29a to 184ae5c Compare August 20, 2024 17:52
@jpobst jpobst marked this pull request as ready for review August 20, 2024 20:19
@jpobst jpobst requested a review from jonpryor August 20, 2024 20:19
@jonpryor jonpryor merged commit 001a03e into main Aug 21, 2024
@jonpryor jonpryor deleted the register-alternatives branch August 21, 2024 21:07
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not [Register] interface alternative classes

2 participants