Xamarin.Mac绑定问题

时间:2015-01-27 07:30:34

标签: binding xamarin.mac

    I am Working on the Xamarin.MAc Project. In my project I need to Use Objective C Code so I going to bind and use in my Xamarin project.

    I am using Objective sharpie for generating the Interface and enum file. that's working fine but i am not able to generate  the .dll file.

    This is my .cs files,



  using System;
    using System.Drawing;
    using MonoMac.Foundation;
    using MonoMac.AppKit;
    using MonoMac.ObjCRuntime;
    using System.Collections.Generic;


    namespace BLVirtualDrive {

        // @interface BaseItemModel : NSObject
        [BaseType (typeof (NSObject))]
        interface BaseItemModel {

            // @property (nonatomic, strong) NSString * name;
            [Export ("name", ArgumentSemantic.Retain)]
            string Name { get; set; }

            // @property unsigned long long id;
            [Export ("id")]
            ulong Id { get; set; }

            // @property unsigned long long parentId;
            [Export ("parentId")]
            ulong ParentId { get; set; }
        }

        // @interface FileModel : BaseItemModel
        [BaseType (typeof (BaseItemModel))]
        interface FileModel {

            // @property unsigned long long currentBufferSize;
            [Export ("currentBufferSize")]
            ulong CurrentBufferSize { get; set; }

            // @property unsigned long long totalFileSize;
            [Export ("totalFileSize")]
            ulong TotalFileSize { get; set; }

            // @property unsigned long long startByte;
            [Export ("startByte")]
            ulong StartByte { get; set; }

            // @property unsigned long long endByte;
            [Export ("endByte")]
            ulong EndByte { get; set; }

            // @property (nonatomic, strong) NSData * data;
            [Export ("data", ArgumentSemantic.Assign)]
            NSData Data { get; set; }
        }

        // @interface FolderModel : BaseItemModel
        [BaseType (typeof (BaseItemModel))]
        interface FolderModel {

        }

        // @interface ContentItemModel : NSObject
        [BaseType (typeof (NSObject))]
        interface ContentItemModel {

            // @property (nonatomic, strong) NSString * itemName;
            [Export ("itemName", ArgumentSemantic.Retain)]
            string ItemName { get; set; }

            // @property unsigned long long itemId;
            [Export ("itemId")]
            ulong ItemId { get; set; }

            // @property unsigned long long currentBufferSize;
            [Export ("currentBufferSize")]
            ulong CurrentBufferSize { get; set; }

            // @property unsigned long long totalItemSize;
            [Export ("totalItemSize")]
            ulong TotalItemSize { get; set; }

            // @property enum ItemType itemType;
            [Export ("itemType")]
            ItemType ItemType { get; set; }

            // @property unsigned long long startByte;
            [Export ("startByte")]
            ulong StartByte { get; set; }

            // @property unsigned long long endByte;
            [Export ("endByte")]
            ulong EndByte { get; set; }

            // @property (nonatomic, strong) NSData * data;
            [Export ("data", ArgumentSemantic.Retain)]
            NSData Data { get; set; }
        }

        // @protocol IVirtualDriveOperations <NSObject>
        [Protocol, Model]
        [BaseType (typeof (NSObject))]
        interface IVirtualDriveOperations{

            // @required -(void)mountVirtualDriveWithItems:(NSArray *)items;
            [Export ("mountVirtualDriveWithItems:")]
            [Abstract]
            void MountVirtualDriveWithItems (NSObject [] items);

            // @required -(void)unMountVirtualDrive;
            [Export ("unMountVirtualDrive")]
            [Abstract]
            void UnMountVirtualDrive ();

            // @required -(id<IVirtualDriveOperations>)getVirtualDriveobject;
            [Export ("getVirtualDriveobject")]
            [Abstract]
            IVirtualDriveOperations GetVirtualDriveobject ();

            // @required -(void)createFile:(FileModel *)fileModel;
            [Export ("createFile:")]
            [Abstract]
            void CreateFile (FileModel fileModel);

            // @required -(void)renameFile:(FileModel *)fileModel;
            [Export ("renameFile:")]
            [Abstract]
            void RenameFile (FileModel fileModel);

            // @required -(void)moveFile:(FileModel *)fileModel;
            [Export ("moveFile:")]
            [Abstract]
            void MoveFile (FileModel fileModel);

            // @required -(void)deleteFile:(FileModel *)fileModel;
            [Export ("deleteFile:")]
            [Abstract]
            void DeleteFile (FileModel fileModel);

            // @required -(void)downloadedFile:(FileModel *)fileModel;
            [Export ("downloadedFile:")]
            [Abstract]
            void DownloadedFile (FileModel fileModel);

            // @required -(void)changeFileContents:(FileModel *)fileModel;
            [Export ("changeFileContents:")]
            [Abstract]
            void ChangeFileContents (FileModel fileModel);

            // @required -(void)createFolder:(FolderModel *)folderModel;
            [Export ("createFolder:")]
            [Abstract]
            void CreateFolder (FolderModel folderModel);

            // @required -(void)renameFolder:(FileModel *)folderModel;
            [Export ("renameFolder:")]
            [Abstract]
            void RenameFolder (FileModel folderModel);

            // @required -(void)moveFolder:(FileModel *)folderModel;
            [Export ("moveFolder:")]
            [Abstract]
            void MoveFolder (FileModel folderModel);

            // @required -(void)deleteFolder:(FileModel *)folderModel;
            [Export ("deleteFolder:")]
            [Abstract]
            void DeleteFolder (FileModel folderModel);
        }
    }

我尝试了类似/Library/Frameworks/Xamarin.Mac.framework/Versions/1.10.0.18/bin/bmac -oBLVirtualDrive.dll --tmpdir = / tmp -baselib = / Library / Frameworks /的命令行工具Xamarin.Mac.framework / Versions / 1.10.0.18 / lib / mono / XamMac.dll -r = System.Drawing IBLVirtualDrive.cs -s = IBLVirtualDriveenums.cs --compiler = mcs --new-style我收到这样的错误错误BI1018:bmac:属性BLVirtualDrive.BaseItemModel.Name上的[Export]属性没有在命令行字段中遗漏的任何内容。

1 个答案:

答案 0 :(得分:1)

也许您需要尝试添加Xamarin.Mac.dll而不是XamMac.dll,并从源中删除MonoMac。

using Foundation;
using AppKit;
using ObjCRuntime;

另外,在Extras.cs文件的顶部添加以下代码:

using System;

[AttributeUsage (AttributeTargets.Method)]
public sealed class MonoPInvokeCallbackAttribute : Attribute {
     public MonoPInvokeCallbackAttribute (Type t) {}
}

您可以在下一个链接https://forums.xamarin.com/discussion/1171/difference-between-bmac-exe-on-xamarin-and-monomac-when-compiling-masshortcutsharp

找到更多信息