Bug 18920 - ISpannable does not include the constants included in the Android Spannable Interface.
Summary: ISpannable does not include the constants included in the Android Spannable I...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-04-09 23:42 UTC by Dustin Graham
Modified: 2014-04-10 11:25 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dustin Graham 2014-04-09 23:42:19 UTC
The Android Spannable interface includes several very important constants which are used to define the styling behavior of SpannableStrings. The Android documentation details these constants:


I believe these should be added to the ISpannable interface to match Android functionality?
Comment 1 Jonathan Pryor 2014-04-10 11:25:11 UTC
This is unfortunately By Design.

The way binding works is we take a .jar (e.g. android.jar), generate an API description via jar2xml, then generate C# source from the API description, then compile the C# source into the binding assembly.

All of the glue code is thus represented in C#, and thus must be valid C#.

Unfortunately, C#'s definition of what's valid within an interface doesn't match Java's: C# interfaces can only contain method, property, and event declarations. No fields, no constants, no nested types, no static methods, etc.

Consequently, the C# ISpannable binding CANNOT contain an ISpannable.SpanExclusiveExclusive member, not without changing the language. (IL should allow this, but who wants to hand-write IL?)

Instead, one of two things is done:

1. The interface constants are mapped to enumerations.

In the case of android.text.Spannable, the constants are present on the SpanTypes enum: http://androidapi.xamarin.com/?link=T%3aAndroid.Text.SpanTypes

2. When the interface constants don't map to an enumeration

In this case, e.g. the android.os.Parcelable interface, the interface methods are moved to a normal C# interface -- IParcelable -- while the interface constants are moved to a type with the same name as the Java interface, in this case Android.OS.Parcelable.

For the same 'C# is our glue" reason, nested types such as android.os.Parcelable.Creator are not nested types, and android.os.Parcelable.Creator is bound as IParcelableCreator: http://androidapi.xamarin.com/?link=T%3aAndroid.OS.IParcelableCreator