从Xamarin.iOS中的Abstract类型类创建对象

时间:2019-06-11 09:43:39

标签: xamarin.ios abstract-class xamarin.ios-binding sightcall

在Xamarin.iOS绑定项目中,我生成了一个名为LSMAUsecase.g.cs的类。以下是该课程的内容。

namespace SightCallBinding {
[Protocol (Name = "LSMAUsecase", WrapperType = typeof (LSMAUsecaseWrapper))]
[ProtocolMember (IsRequired = true, IsProperty = true, IsStatic = false, Name = "Name", Selector = "name", PropertyType = typeof (string), GetterSelector = "name", ArgumentSemantic = ArgumentSemantic.None)]
public interface ILSMAUsecase : INativeObject, IDisposable
{
    [Preserve (Conditional = true)]
    string Name {
        [Export ("name")]
        get;
    }   
}

internal sealed class LSMAUsecaseWrapper : BaseWrapper, ILSMAUsecase {
    [Preserve (Conditional = true)]
    public LSMAUsecaseWrapper (IntPtr handle, bool owns)
        : base (handle, owns)
    {
    }

    [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    public string Name {
        [Export ("name")]
        get {
            return NSString.FromHandle (global::ApiDefinitions.Messaging.IntPtr_objc_msgSend (this.Handle, Selector.GetHandle ("name")));
        }

    }

}

}

namespace SightCallBinding {
[Protocol()]
[Register("LSMAUsecase", false)]
[Model]


 public unsafe abstract partial class LSMAUsecase : NSObject, ILSMAUsecase {

    [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    [EditorBrowsable (EditorBrowsableState.Advanced)]
    [Export ("init")]
    protected LSMAUsecase () : base (NSObjectFlag.Empty)
    {
        IsDirectBinding = false;
        InitializeHandle (global::ApiDefinitions.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
    }

    [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    [EditorBrowsable (EditorBrowsableState.Advanced)]
    protected LSMAUsecase (NSObjectFlag t) : base (t)
    {
        IsDirectBinding = false;
    }

    [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    [EditorBrowsable (EditorBrowsableState.Advanced)]
    protected internal LSMAUsecase (IntPtr handle) : base (handle)
    {
        IsDirectBinding = false;
    }

    [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    public abstract string Name {
        [Export ("name")]
        get; 
    }

} /* class LSMAUsecase */
}

我想将LSMaUsecase对象传递给方法。但是我不能从中创建任何对象,因为它是一个抽象类。而且我什至不能转换为LSMAUsecase类型。它说,无效的演员。有什么方法可以解决此问题如何传递这种类型的对象。以下是界面中的相关方法。

    [BindingImpl(BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
    [Export("sendInvitationForUsecasePhone:toPhone:withReference:andNotify:")]
    [Preserve(Conditional = true)]
    void SendInvitationForUsecasePhone(LSMAUsecase usecase, string phoneNumber, string reference, [BlockProxy(typeof(NIDActionArity2V0))] Action<LSMAPincodeStatus_t, NSString> block);

更新

这是我的扩展课程

public class Usecase : LSMAUsecase
{
    public override string Name { get; }
    public Usecase()
        : base()
    {

    }

}

然后我收到此异常,因为我没有“名称”的任何值(名称仅获取)。

  

Foundation.MonoTouchException:引发Objective-C异常。名称:   NSInvalidArgumentException原因:-[LSMAHandler   sendInvitationForUsecasePhone:toPhone:withReference:andNotify:]:   无法识别的选择器已发送到实例0x282458780

0 个答案:

没有答案