[generator] Only apply ConstSugar to Mono.Android.dll. #780
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #752
The Android API has an "interesting" pattern where they have an interface with some static constants, and then they inherit that interface in other types to inherit those constants.
Example: https://developer.android.com/reference/android/provider/BaseColumns
This interface is inherited by ~115 other types, including other interfaces that only have static constant fields, like CalendarContract.CalendarSyncColumns . This made a very messy API when we bound it due the constants being copied into our alternative
IBaseColumnsConstsandICalendarSyncColumnsConstsclasses. Therefore we decided to call this pattern "ConstSugar" and we wrote code to remove these interfaces that did not provide value in the managed API.However this logic is applied to all binding libraries, and there can exist marker interfaces that meet the same criteria as ConstSugar, and they get silently removed from binding libraries.
In this example we would not bind
CanJsonSerialize. Worse, an interface can go from not being considered ConstSugar to triggering ConstSugar simply by additions to an API. IfCanSerializeoriginally had no fields, both interfaces would be generated. OnceVERSIONis added,CanJsonSerializeis considered ConstSugar and will get removed.Since this logic is very specific to
Mono.Android, we're going to useCodeGenerationOptions.BuildingCoreAssemblyto determine if we're buildingMono.Android.dll, and only run ConstSugar logic if true. This will prevent the logic from running on user binding projects and causing unexplained missing API for users.