Skip to content

Add multiple AlsoUsableFor for autotype #2208

@wherewhere

Description

@wherewhere

In C++, we can have:

class _jobject {};
class _jarray : public _jobject {};
class _jbooleanArray : public _jarray {};

typedef _jobject *jobject;
typedef _jarray *jarray;
typedef _jbooleanArray *jbooleanArray;

So that jbooleanArray can implicit convert to jarray and jobject. Now we can use [AlsoUsableFor("jarray")] to mark jbooleanArray can implicit convert to jarray or [AlsoUsableFor("jobject")] to mark jbooleanArray can implicit convert to jobject, but we cannot mark them both. If we mark the [AlsoUsableFor("jarray")] for jbooleanArray and [AlsoUsableFor("jobject")] for jarray, we need to implicit convert jbooleanArray to jarray and then implicit convert it to jobject. For example:

JValue* _args = stackalloc JValue[1];
JClass stringClass = env->functions->FindClass.CreateDelegate<FindClass>().Value(env, "java/lang/String"u8.AsPCSTR());
_args[0].l = (JArray)env->functions->NewObjectArray.CreateDelegate<NewObjectArray>().Value(env, 0, stringClass, default);
env->functions->CallStaticVoidMethodA.CreateDelegate<CallStaticVoidMethodA>().Value(env, mainClass, entryPoint, _args);

So, it will be better if we can have [AlsoUsableFor(["jarray", "jobject"])] or can multiple mark AlsoUsableFor like [AlsoUsableFor(["jarray"])][AlsoUsableFor("jobject")] so that we can direct implicit convert jbooleanArray to jobject.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions