本文整理汇总了C#中TransferDataType.ToUTI方法的典型用法代码示例。如果您正苦于以下问题:C# TransferDataType.ToUTI方法的具体用法?C# TransferDataType.ToUTI怎么用?C# TransferDataType.ToUTI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransferDataType
的用法示例。
在下文中一共展示了TransferDataType.ToUTI方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetData
public override void SetData (TransferDataType type, Func<object> dataSource)
{
var pboard = NSPasteboard.GeneralPasteboard;
pboard.ClearContents ();
owner.DataSource = dataSource;
pboard.AddTypes (new[] { type.ToUTI () }, owner);
}
示例2: SetData
public override void SetData (TransferDataType type, Func<object> dataSource, bool cleanClipboardFirst = true)
{
var pboard = NSPasteboard.GeneralPasteboard;
if(cleanClipboardFirst) {
pboard.ClearContents();
}
var owner = new PasteboardOwner();
owner.DataSource = dataSource;
pboard.AddTypes (new[] { type.ToUTI () }, owner);
}
示例3: GetData
public override object GetData (TransferDataType type)
{
if (type == TransferDataType.Uri)
return (Uri)NSUrl.FromPasteboard (NSPasteboard.GeneralPasteboard);
var data = NSPasteboard.GeneralPasteboard.GetDataForType (type.ToUTI ());
if (data == null)
return null;
if (type == TransferDataType.Text)
return data.ToString ();
if (type == TransferDataType.Image)
return new NSImage (data);
unsafe {
var bytes = new byte [data.Length];
using (var stream = new UnmanagedMemoryStream ((byte*)data.Bytes, bytes.Length))
stream.Read (bytes, 0, bytes.Length);
return TransferDataSource.DeserializeValue (bytes);
}
}
示例4: IsTypeAvailable
public override bool IsTypeAvailable(TransferDataType type)
{
return NSPasteboard.GeneralPasteboard.Types.Contains (type.ToUTI ());
}
示例5: IsTypeAvailable
public override bool IsTypeAvailable (TransferDataType type)
{
return NSPasteboard.GeneralPasteboard.CanReadItemWithDataConformingToTypes (new[] { type.ToUTI () });
}
示例6: IsTypeAvailable
public override bool IsTypeAvailable (TransferDataType type)
{
NSPasteboard pb = NSPasteboard.GeneralPasteboard;
#if MONOMAC
NSObject[] classes;
#else
Class[] classes;
#endif
NSDictionary options;
bool isType;
if (pb.PasteboardItems.Length == 0) {
return false;
}
if (type == TransferDataType.Image) {
//The below only works for images copied from web browsers, doesn't work for raw images.
// NSObject urlClassObj = NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSUrl)));
// NSObject imageClassObj = NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSImage)));
// classes = new NSObject[]{ urlClassObj };
// NSObject a = new NSString(type.ToUTI());
// options = NSDictionary.FromObjectAndKey(imageClassObj, a);
// isType = pb.CanReadObjectForClasses(classes, options);
// return isType;
var item = pb.PasteboardItems[0];
foreach (string itemType in item.Types) {
if (itemType == "public.tiff" || itemType == "public.png") {
return true;
}
}
return false;
} else if (type == TransferDataType.Text) {
// text
var item = pb.PasteboardItems[0];
foreach (string itemType in item.Types) {
if (itemType == "public.file-url") {
return true;
}
}
#if MONOMAC
classes = new NSObject[] {
NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSAttributedString))),
NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSString))),
NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSUrl))),
};
#else
classes = new Class[] {
new Class(typeof(NSAttributedString)),
new Class(typeof(NSString)),
new Class(typeof(NSUrl)),
};
#endif
options = new NSDictionary();
isType = pb.CanReadObjectForClasses(classes, options);
return isType;
} else if (type == TransferDataType.Uri) {
//files
#if MONOMAC
classes = new NSObject[]{ NSObject.FromObject(new MonoMac.ObjCRuntime.Class(typeof(NSUrl))) };
#else
classes = new Class[]{ new Class(typeof(NSUrl)) };
#endif
options = NSDictionary.FromObjectAndKey(NSObject.FromObject(NSNumber.FromBoolean(true)), new NSString(type.ToUTI()));
isType = pb.CanReadObjectForClasses(classes, options);
return isType;
}
return NSPasteboard.GeneralPasteboard.Types.Contains (type.ToUTI ());
}
示例7: GetData
public override object GetData (TransferDataType type)
{
if (type == TransferDataType.Uri) {
NSPasteboard pasteBoard = NSPasteboard.GeneralPasteboard;
NSArray nsArray = (NSArray)pasteBoard.GetPropertyListForType(NSPasteboard.NSFilenamesType);
NSString[] pathArray = NSArray.FromArray<NSString>(nsArray);
if(pathArray != null) {
string[] uriArray = new string[pathArray.Length];
for(int i = 0; i < pathArray.Length; i++) {
Uri fileUrl = new Uri(pathArray[i].ToString());
if(fileUrl != null && fileUrl.IsFile) {
uriArray[i] = pathArray[i].ToString();
}
}
return uriArray;
}
}
if(type == TransferDataType.Image) {
NSPasteboard pasteBoard = NSPasteboard.GeneralPasteboard;
string[] imageTypes = NSImage.ImageUnfilteredPasteboardTypes();
for (int i = 0; i< imageTypes.Length; i++) {
NSData imgData = pasteBoard.GetDataForType(imageTypes[i]);
if(imgData != null) {
NSImage nsImg = new NSImage(imgData);
return ApplicationContext.Toolkit.WrapImage (nsImg);
}
}
}
// Url as text!
if (type == TransferDataType.Text) {
NSUrl url = NSUrl.FromPasteboard(NSPasteboard.GeneralPasteboard);
if(url != null && url.IsFileUrl) {
return "file://" + new Uri(url.Path).AbsolutePath;
}
}
var data = NSPasteboard.GeneralPasteboard.GetDataForType (type.ToUTI ());
if (data == null)
return null;
if (type == TransferDataType.Text)
return data.ToString ();
if (type == TransferDataType.Image)
return ApplicationContext.Toolkit.WrapImage (new NSImage (data));
unsafe {
var bytes = new byte [data.Length];
using (var stream = new UnmanagedMemoryStream ((byte*)data.Bytes, bytes.Length))
stream.Read (bytes, 0, bytes.Length);
try {
return TransferDataSource.DeserializeValue(bytes);
} catch(System.Runtime.Serialization.SerializationException) {
// if data cannot be read, do not crash - return null
return null;
}
}
}