ExportAttribute() is inaccessible due to its prote

2019-07-24 01:05发布

问题:

I am converting our source code to use Xamarin.iOS unified api (rather painfully... Xamarin). Currently I have a bunch of errors of this flavor:

ExportAttribute() is inaccessible due to its protection level

I understand there is no longer a public parameter-less constructor - so what am I supposed to provide the ExportAttribute constructor to get this to work - I am not the original author of this code so I am not exactly sure what to do here. I have a method like this:

  [Foundation.Export()]
  private void CameraSnapshotComplete()
  {
  }

What do I pass to the ExportAttribute constructor in tihs case? This method is being sent to the AnimationDidStop method like this:

  UIView.SetAnimationDidStopSelector(new ObjCRuntime.Selector("CameraSnapshotComplete"));

So do I just pass "CameraSnapshotComplete" to the constructor? I have a zillion of these to replace - so would like a little feedback before I start doing this and find out I am doing it wrong.

回答1:

If the selector is named CameraSnapshotComplete then the [Export] attribute must use the same name. IOW if you call it like this:

UIView.SetAnimationDidStopSelector(new ObjCRuntime.Selector("CameraSnapshotComplete"));

then the method should be exported like:

[Foundation.Export("CameraSnapshotComplete")]
private void CameraSnapshotComplete()
{
}

In many cases there are API alternative, to using selectors, that will make the code more strongly typed (and avoid potential typos that are hard to debug).