Esempio n. 1
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo" />. If null is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <param name="destinationType">The <see cref="T:System.Type" /> to convert the <paramref name="value" /> parameter to.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (value != null)
            {
                string        valueContent = value.ToString();
                IMediaService mediaService = ConverterHelper.GetMediaService();
                IMedia        media        = mediaService.GetMediaByPath(valueContent);
                if (media != null)
                {
                    return(media.Id);
                }
            }

            // Always call base, even if you can't convert.
            return(base.ConvertTo(context, culture, value, destinationType));
        }