Create an object from Abstract type class in Xamarin.iOS

283 Views Asked by At

In my Xamarin.iOS binding project, I have a generated class called LSMAUsecase.g.cs. following is the content of that class.

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 */
}

I want to pass LSMaUsecase object to a method. But I cannot create any object from this since it is an abstract class. And I cannot even cast into LSMAUsecase type. It says, invalid cast. Is there any way to resolve this How can I pass this type of object. following is the related method in the interface.

    [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);

UPDATE

This is my extended class

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

    }

}

Then I am getting this exception since I don't have any value for "Name"(Name is get only).

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[LSMAHandler sendInvitationForUsecasePhone:toPhone:withReference:andNotify:]: unrecognized selector sent to instance 0x282458780

0

There are 0 best solutions below