gpt4 book ai didi

macos - Xamarin 中的 MDItem 类

转载 作者:行者123 更新时间:2023-12-03 17:01:42 26 4
gpt4 key购买 nike

我正在尝试从文件中读取评论字段。 enter image description here

找到this thread关于如何做到这一点,但在Xamarin中找不到MDItem相应的类。

有什么想法可以在哪里找到它或者用什么来代替吗?

最佳答案

某些 CoreServices 未包含在当前 Xamarin.Mac 中(版本:2.10.0.57)。

它们中的大多数传递基于CFxxxx的引用,因此它们很容易通过一些互操作调用来包装和实现。

基于Finder的文件注释

enter image description here

代码示例:

var fileURL = NSUrl.FromString("/Users/sushi/Desktop/DFeedback_FeedBack.png");
var mMDItemRef = MDItemCreateWithURL(IntPtr.Zero, fileURL.Handle);

var mCFTypeRef = MDItemCopyAttribute(mMDItemRef, new CFString("kMDItemFinderComment").Handle);
var finderComment = NSString.FromHandle(mCFTypeRef);
Console.WriteLine(finderComment);

注意:应在生产代码中测试互操作调用是否为空,请参阅头文件中的返回签名注释。

应用程序输出:

StackOverflow

互操作设置:

// @function MDItemCreateWithURL
// Returns an metadata item for the given path.
// @param allocator The CFAllocator which should be used to allocate
// memory for the query and its sub-storage.This
// parameter may be NULL in which case the current default
// CFAllocator is used.
// @param url A url to the file for which to create the MDItem.
// [[Currently, the file must exist.MDItemRefs may or
// may not be uniqued.Use CFEqual() to compare them.]]
// @result An MDItemRef, or NULL on failure.

//MD_EXPORT MDItemRef MDItemCreateWithURL(CFAllocatorRef allocator, CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
[DllImport(Constants.CoreServicesLibrary)]
extern static /* MDItemRef */ IntPtr MDItemCreateWithURL(/* CFAllocatorRef __nullable */ IntPtr allocator, /* CFURLRef */ IntPtr inURL);

//@function MDItemCopyAttribute
//Returns the value of the given attribute for the item.
//@param item The item to be interrogated.
//@param name The name of the desired attribute.
//@result A CFTypeRef, or NULL on failure, or if the attribute
//does not exist, of if the attribute is not readable.

//MD_EXPORT CFTypeRef MDItemCopyAttribute(MDItemRef item, CFStringRef name) MD_AVAIL;
[DllImport(Constants.CoreServicesLibrary)]
extern static /* CFTypeRef */ IntPtr MDItemCopyAttribute(/* MDItemRef */ IntPtr item, /* CFStringRef */ IntPtr name);

Xcode Obj-C header 引用:

MDItem.h

本地 Xcode 引用::/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Headers

关于macos - Xamarin 中的 MDItem 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38952536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com