Xamarin: Interface and Protocol inheritance issue.

(BMS) Jack 1 Reputation point
2021-04-20T00:23:19.777+00:00
  • Background:
    • I'm using Xamarin: Forms using Visual Studio for Mac.
    • I'm integrating the Brother Print SDK v4.
    • I have successfully used Objective Sharpie and adjusted the ApiDefinitions.cs and Structs.cs files to work with v3 SDK.
    • v4 SDK uses Protocols and Interfaces slightly differently than its predecessor.
  • Problem:
    • I have an interface:
      //apidefinitions.cs
    // @ENA IBRLMPrintSettingsProtocol <NSObject>
    /*
    Check whether adding [Model] to this declaration is appropriate.
    [Model] is used to generate a C# class that implements this protocol,
    and might be useful for protocols that consumers are supposed to implement,
    since consumers can subclass the generated class instead of implementing
    the generated interface. If consumers are not supposed to implement this
    protocol, then [Model] is redundant and will generate code that will never
    be used.
    */
    [Protocol, Model]
    [BaseType(typeof(NSObject))]
    [DisableDefaultCtor]
    interface IBRLMPrintSettingsProtocol
    {
    // @required -(instancetype _Nullable)initDefaultPrintSettingsWithPrinterModel:(BRLMPrinterModel)model;
    [Abstract]
    [Export("initDefaultPrintSettingsWithPrinterModel:")]
    [return: NullAllowed]
    IntPtr initDefaultPrintSettingsWithPrinterModel(BRLMPrinterModel model);
    }
  • I have some code:
    //apidefinitions.cs
    interface BRLMRJPrintSettings : INSCoding, IBRLMPrintSettingsProtocol, IBRLMPrintImageSettings
    { // stuff }
     //printingClass.cs  
     BRLMRJPrintSettings rjPrintSettings;  
     BRLMChannel brlmChannel;  
     BRLMPrinterDriver printerDriver;  
    
     rjPrintSettings.initDefaultPrintSettingsWithPrinterModel(BRLMPrinterModel.Rj4230b);  
     BRLMPrinterDriverGenerateResult printerDriverGenerateResult = BRLMPrinterDriverGenerator.OpenChannel(brlmChannel);  
     printerDriver = printerDriverGenerateResult.Driver;  
    
  • The Problem Code:
    //printingClass.cs
    var brlmPrintError = printerDriver.PrintPDFWithURL(fileUri,rjPrintSettings);
  • Definition:
    //apidefinitions.cs
    BRLMPrintError PrintPDFWithURL(NSUrl url, IBRLMPrintSettingsProtocol settings);

My understanding is that the RJPrintSettings object should be "interchangeable" with the IBRLMPrintSettingsProtocol.
However, I get the following:
CS1503: Argument 2: cannot convert from 'iosBinding.BRLMRJPrintSettings' to 'iosBinding.IBRLMPrintSettingsProtocol'

I've done everything I can think of, but have been unable to resolve this issue. Any suggestions?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,818 questions
No comments
{count} votes