You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[generator] Add support for const fields on interfaces (#439)
Add support for Java-side interface constants to be optionally bound
using C# 8.0's new default interface member support. This is
feature-flagged behind the `--lang-features=interface-constants`
option (off by default):
generator --lang-features=interface-constants ...
Here is an example of what is generated from `Mono.Android.dll`:
// Metadata.xml XPath interface reference: path="/api/package[@name='android.os']/interface[@name='Parcelable']"
[Register ("android/os/Parcelable", "", "Android.OS.IParcelableInvoker", ApiSince = 1)]
public partial interface IParcelable : IJavaObject {
+ // Metadata.xml XPath field reference: path="/api/package[@name='android.os']/interface[@name='Parcelable']/field[@name='CONTENTS_FILE_DESCRIPTOR']"
+ [Register ("CONTENTS_FILE_DESCRIPTOR")]
+ public const int ContentsFileDescriptor = (int) 1;
// Metadata.xml XPath method reference: path="/api/package[@name='android.os']/interface[@name='Parcelable']/method[@name='describeContents' and count(parameter)=0]"
[Register ("describeContents", "()I", "GetDescribeContentsHandler:Android.OS.IParcelableInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
int DescribeContents ();
// Metadata.xml XPath method reference: path="/api/package[@name='android.os']/interface[@name='Parcelable']/method[@name='writeToParcel' and count(parameter)=2 and parameter[1][@type='android.os.Parcel'] and parameter[2][@type='int']]"
[Register ("writeToParcel", "(Landroid/os/Parcel;I)V", "GetWriteToParcel_Landroid_os_Parcel_IHandler:Android.OS.IParcelableInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
void WriteToParcel (Android.OS.Parcel dest, [global::Android.Runtime.GeneratedEnum] Android.OS.ParcelableWriteFlags flags);
}
There are several Android interfaces defined that only contain
constants. Without Default-Interface-Methods, we have not been
generating these interfaces because there was nothing we could
generate for them. (These are referred to as `IsConstSugar`). Now
we generate them, but they do not have `[Register]` on the interface
and do not inherit from `IJavaObject` since they are not used for
Java interop, e.g. [`android.icu.lang.UProperty.NameChoice][0]:
[0]: https://developer.android.com/reference/android/icu/lang/UProperty.NameChoice
// Metadata.xml XPath interface reference: path="/api/package[@name='android.icu.lang']/interface[@name='UProperty.NameChoice']"
public partial interface IUPropertyNameChoice {
// Metadata.xml XPath field reference: path="/api/package[@name='android.icu.lang']/interface[@name='UProperty.NameChoice']/field[@name='LONG']"
[Register ("LONG")]
public const int Long = (int) 1;
// Metadata.xml XPath field reference: path="/api/package[@name='android.icu.lang']/interface[@name='UProperty.NameChoice']/field[@name='SHORT']"
[Register ("SHORT")]
public const int Short = (int) 0;
}
Here is the diff of this change run on `Mono.Android.dll`:
https://gist.github.com/jpobst/7aa0bb1a01975a56038cb7ab12ecdb1c
0 commit comments