/// <summary>
        /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data. </param><param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization. </param><exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //only support "serialization" in same application through shared object cache
            Guid ObjectId = Guid.NewGuid();

            DragDropObjectWrapper.AddObject(ObjectId, this.DragData);
            info.AddValue("ID", ObjectId.ToString());
        }
        private static IDataObject GetObject(Guid objectId)
        {
            DragDropObjectWrapper.RemoveCollectedObjects();
            if (DragDropObjectWrapper.objectCache.ContainsKey(objectId))
            {
                IDataObject Target;
                bool        CouldGetTarget = DragDropObjectWrapper.objectCache[objectId].TryGetTarget(out Target);

                return(CouldGetTarget ? Target : null);
            }
            else
            {
                return(null);
            }
        }
 private static void AddObject(Guid objectId, IDataObject dataObject)
 {
     DragDropObjectWrapper.RemoveCollectedObjects();
     DragDropObjectWrapper.objectCache.Add(objectId, new WeakReference <IDataObject>(dataObject));
 }
        ///<summary>
        /// Constructor for deserialisation
        ///</summary>
        public DragDropObjectWrapper(SerializationInfo info, StreamingContext context)
        {
            Guid ObjectId = new Guid(info.GetString("ID"));

            this.DragData = DragDropObjectWrapper.GetObject(ObjectId);
        }