java.interop icon indicating copy to clipboard operation
java.interop copied to clipboard

Constructor with ExportAttribute loses managed parameters

Open outring opened this issue 9 years ago • 4 comments

Hi!

When a class constructor is decorated with [Export] in order to provide super arguments string, TypeManager.Activate() call loses constructor parameters types info and wrong (parameterless) constructor is being called instead.

MyView.cs:

public class MyView : Android.Views.View {
       public ItemFieldView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
        {
        }

        [Export(SuperArgumentsString = "p0, null, proj.droid.proj.droid.R.attr.itemFieldStyle")]
        public MyView(Context context)
            : base(context, null, Resource.Attribute.myViewStyle)
        {
        }

        [Export(SuperArgumentsString = "p0, p1, proj.droid.proj.droid.R.attr.itemFieldStyle")]
        public MyView(Context context, IAttributeSet attrs)
            : base(context, attrs, Resource.Attribute.myViewStyle)
        {
        }

        public MyView(Context context, IAttributeSet attrs, int defStyleAttr)
            : base(context, attrs, defStyleAttr)
        {
        }

        public MyView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes)
            : base(context, attrs, defStyleAttr, defStyleRes)
        {
        }
}

The reason is that managedParameters are just not being passed to a new Signature at https://github.com/xamarin/java.interop/blob/master/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs#L251

outring avatar Dec 23 '16 13:12 outring

Export attribute is NOT supported on constructors.

atsushieno avatar Jan 17 '17 09:01 atsushieno

Hi, @atsushieno! Since when? Because according to the code it works. And, of course, according to this ticket.

outring avatar Jan 17 '17 09:01 outring

It's not supported as in that its implementation is hacky and won't work other than those described on that bug. That cannot be at "supported" state.

Though it's looking something @jonpryor can take a look and fix, if that change makes it to work for you.

atsushieno avatar Jan 17 '17 09:01 atsushieno

If it's not so important to you can leave it as is, and I'll fix it when I find some time for it.

outring avatar Jan 17 '17 09:01 outring