Esempio n. 1
0
        public static bool TryGetWrappedData(this IDataObject data, string dataFormat, DataObjectStorage storage, out IEnumerable <object> wrappedData)
        {
            // Retrieve wrapped data of the specified format and storage type
            string wrappedFormat        = GetWrappedDataFormat(dataFormat, storage);
            SerializableWrapper wrapper = data.GetData(wrappedFormat) as SerializableWrapper;

            if (wrapper != null && wrapper.Data != null && wrapper.Data.Count > 0)
            {
                wrappedData = wrapper.Data;
                return(true);
            }

            // If retrieving by-value failed, try retrieving by-reference and cloning the result
            if (storage == DataObjectStorage.Value)
            {
                IEnumerable <object> byReferenceData;
                if (data.TryGetWrappedData(dataFormat, DataObjectStorage.Reference, out byReferenceData))
                {
                    wrappedData = byReferenceData.Select(obj => obj.DeepClone()).ToArray();
                    return(true);
                }
            }

            wrappedData = null;
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the specified non-<see cref="SerializableAttribute"/> data from the specified data object using a serializable wrapper.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static object GetWrappedData(this IDataObject data, string format)
        {
            SerializableWrapper wrapper = data.GetData(WrapperPrefix + format) as SerializableWrapper;

            if (wrapper != null)
            {
                return(wrapper.Data);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Stores the specified non-<see cref="SerializableAttribute"/> data inside the specified data object using a serializable wrapper.
        /// </summary>
        /// <param name="dataFormat">The format of the data being stored</param>
        /// <param name="storage">The type of data being stored</param>
        public static void SetWrappedData(this IDataObject data, IEnumerable <object> values, string dataFormat, DataObjectStorage storage)
        {
            object[]            valuesArr     = values.ToArray();
            string              wrappedFormat = GetWrappedDataFormat(dataFormat, storage);
            SerializableWrapper wrapper       = storage == DataObjectStorage.Reference
                                ? new SerializableReferenceWrapper(valuesArr)
                                : new SerializableWrapper(valuesArr);

            data.SetData(wrappedFormat, wrapper);

            // Reference data is automatically stored as a value as well
            if (storage == DataObjectStorage.Reference)
            {
                data.SetWrappedData(valuesArr, dataFormat, DataObjectStorage.Value);
            }
        }