2012-02-28 66 views
3

如果我有以下的(一个协议,然后一个接口,它使用该协议),什么是设立btouch的ApiDefinition正确的方法是什么?我已经转换了大部分.h文件,但是这个文件正在欺骗我。的MonoTouch绑定语法对于协议

感谢

杰夫

@protocol GRGrabbaPreferencesProtocol <NSObject> 
- (NSString*) baseNamepace; 
@end 

@interface GRGrabbaPreferences : NSObject <GRGrabbaPreferencesProtocol> 
{ 
    GRGrabbaBarcodePrefs *barcode; 
} 
@property (retain) GRGrabbaBarcodePrefs *barcode; 
@end 

@interface GRGrabbaBarcodePrefs : NSObject <GRGrabbaPreferencesProtocol> 
@end 

回答

4

协议实际上只是联到你的界面,让您可以只直接内联属性到类,也可以有发电机内联的为您服务。

// Notice the lack of [BaseType] attribute on this one 
interface GRGrabbaPreferencesProtocol { 
    [Export ("baseName")] 
    string BaseName { get; } 
} 

[BaseType (typeof (NSObject))] 
interface GRGrabbaPreferences : GRGrabbaPreferencesProtocol { 
    [Export ("barcode")] 
    GRGrabbaBarcodePrefs Barcode { get; } 
} 

[BaseType (typeof (NSObject))] 
interface GRGrabbaBarcodePrefs : GRGrabbaPreferencesProtocol { 
} 

以上是相同的:

[BaseType (typeof (NSObject))] 
interface GRGrabbaPreferences : GRGrabbaPreferencesProtocol { 
    [Export ("baseName")] 
    string BaseName { get; } 

    [Export ("barcode")] 
    GRGrabbaBarcodePrefs Barcode { get; } 
} 

[BaseType (typeof (NSObject))] 
interface GRGrabbaBarcodePrefs : GRGrabbaPreferencesProtocol { 
    [Export ("baseName")] 
    string BaseName { get; } 
} 

更实用让发电机接管内联,以避免错误和剪切/粘贴问题。但请注意,没有GRGrabbaPreferencesProtocol以任何形式导出到C#。