コード例 #1
0
        protected void ProvideWebArchive(NSPasteboard pboard, NSPasteboardItem item, string type)
        {
            // This method does not seem to work any more. Disabled by not returning appropriate type in Types getter.
            var s = GetHtmlWithoutMetadata();

            if (s == null)
            {
                return;
            }

            var mainRsrc = new NSDictionary
            {
                ["WebResourceData"]             = NSData.FromString(s, NSStringEncoding.UTF8),
                ["WebResourceFrameName"]        = (NSString)"",
                ["WebResourceMIMEType"]         = (NSString)"text/html",
                ["WebResourceTextEncodingName"] = (NSString)"UTF-8",
                ["WebResourceURL"] = (NSString)"about:blank"
            };

            var container = new NSDictionary
            {
                ["WebMainResource"] = mainRsrc
            };

            var nsdata  = NSPropertyListSerialization.DataWithPropertyList(container, NSPropertyListFormat.Xml, out NSError error);
            var archive = NSString.FromData(nsdata, NSStringEncoding.UTF8);

            item.SetDataForType(nsdata, Pasteboard.NSPasteboardTypeWebArchive);
        }
コード例 #2
0
        static byte[] Serialize(NSDictionary plist)
        {
            NSError error;
            var     nsData = NSPropertyListSerialization.DataWithPropertyList(plist, NSPropertyListFormat.Xml, out error);

            if (nsData == null)
            {
                throw new Exception("Failed to serialize plist");
            }

            return(Encoding.UTF8.GetBytes(nsData.ToString()));
        }