背景:
- 我正在使用 Xamarin:使用 Visual Studio for Mac 的表单。
- 我正在集成 Brother Print SDK v4。
- 我已成功使用 Objective Sharpie 并调整 ApiDefinitions.cs 和 Structs.cs 文件以使用 v3 SDK。
- v4 SDK 使用的协议和接口与其前身略有不同。
问题:
我有一个界面:
//apidefinitions.cs
// @protocol 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);
}
我有一些代码:
//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;
问题:
//printingClass.cs
var brlmPrintError = printerDriver.PrintPDFWithURL(fileUri,rjPrintSettings);
Definition:
//apidefinitions.cs
BRLMPrintError PrintPDFWithURL(NSUrl url, IBRLMPrintSettingsProtocol settings);
我的理解是 RJPrintSettings 对象应该与 IBRLMPrintSettingsProtocol “可互换”。但是,我得到以下信息:
CS1503: Argument 2: cannot convert from iosBinding.BRLMRJPrintSettings to iosBinding.IBRLMPrintSettingsProtocol
我已经做了我能想到的一切,但一直无法解决这个问题。有什么建议么?