美好的一天,我該如何實作以下功能?在 xamarin 上
public IntPtr Handle => throw new NotImplementedException();
public int JniIdentityHashCode => throw new NotImplementedException();
public JniObjectReference PeerReference => throw new NotImplementedException();
public JniPeerMembers JniPeerMembers => throw new NotImplementedException();
public JniManagedPeerStates JniManagedPeerState => throw new NotImplementedException();
uj5u.com熱心網友回復:
在 xamarin 中,如果我們實作介面,我們需要從類Java.Lang.Object以及介面本身繼承,正如 Trevor Balcom 所提到的。
假設你的界面是ITestClientListener,我們可以這樣做:
public class TestClientListener : Java.Lang.Object, ITestClientListener
{
public JniManagedPeerStates JniManagedPeerState()
{
throw new NotImplementedException();
}
IntPtr ITestClientListener.Handle()
{
throw new NotImplementedException();
}
int ITestClientListener.JniIdentityHashCode()
{
throw new NotImplementedException();
}
JniPeerMembers ITestClientListener.JniPeerMembers()
{
throw new NotImplementedException();
}
JniObjectReference ITestClientListener.PeerReference()
{
throw new NotImplementedException();
}
}
我們可以像這樣使用它的實體:
//create a new object
TestClientListener listener = new TestClientListener();
// use it as you need
筆記:
如果需要,您需要在類的上述方法中添加必要的代碼TestClientListener .cs。
uj5u.com熱心網友回復:
Android 專案中的 C# 物件應繼承自Java.Lang.Object.
public class YourCSharpObject : Java.Lang.Object
{
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/449254.html
標籤:C# 视觉工作室 xamarin xamarin.forms xamarin.android
