2012-02-28 39 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#。