예제 #1
0
        /// <summary>
        /// Gets the all MimeItems of a given MIME type
        /// </summary>
        /// <returns>The MimeItems.</returns>
        /// <param name="mimeItemCollection">MIME item collection.</param>
        /// <param name="mimeType">MIME type.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static List <MimeItem <T> > GetMimeItems <T>(this IMimeItemCollection mimeItemCollection, string mimeType)
        {
            mimeType = mimeType.ToLower();
            var mimeItems = new List <MimeItem <T> >();

            /*
             * var untypedMimeItems = clipboardEntry.Items.FindAll((mi) => mi.MimeType == mimeType);
             * if (untypedMimeItems != null && untypedMimeItems.Count > 0)
             *  foreach (var untypedMimeItem in untypedMimeItems)
             *      if (MimeItem<T>.Create(untypedMimeItem) is MimeItem<T> item)
             *          mimeItems.Add(item);
             */
            foreach (var item in mimeItemCollection.Items)
            {
                if (item.MimeType == mimeType)
                {
                    mimeItems.Add(MimeItem <T> .Create(item));
                }
            }
            return(mimeItems);
        }
예제 #2
0
        /// <summary>
        /// Gets the first MimeItem of a given MIME type.
        /// </summary>
        /// <returns>The first MIME item.</returns>
        /// <param name="mimeItemCollection">MimeItemCollection.</param>
        /// <param name="mimeType">MIME type.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static MimeItem <T> GetFirstMimeItem <T>(this IMimeItemCollection mimeItemCollection, string mimeType)
        {
            //MimeItem<T> result = null;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            mimeType = mimeType.ToLower();
            foreach (var item in mimeItemCollection.Items)
            {
                if (item.MimeType == mimeType)
                {
                    stopwatch.Stop();
                    //System.Diagnostics.Debug.WriteLine("\t\t GetFirstMimeItem<T> elapsed: " + stopwatch.ElapsedMilliseconds);
                    return(MimeItem <T> .Create(item));
                }
            }
            //var untypedMimeItem = clipboardEntry.Items.FirstOrDefault((mi) => mi.MimeType == mimeType);
            return(null);
        }