コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public object ConvertFromString(string value)
        {
            object result = Activator.CreateInstance <T>();

            NameValueCollectionHelper.SetNameValueCollection(ref result, NameValueCollectionHelper.Parse(value));
            return(result);
        }
コード例 #2
0
        /// <summary>
        ///     Attempts to convert to a DoubleDataSourceItemInfo from the given object.
        /// </summary>
        /// <returns>
        ///     The DoubleDataSourceItemInfo which was constructed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        ///     A NotSupportedException is thrown if the example object is null or is not a valid type
        ///     which can be converted to a DoubleDataSourceItemInfo.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The requested CultureInfo.  Note that conversion uses "en-US" rather than this parameter. </param>
        /// <param name="value"> The object to convert to an instance of DoubleDataSourceItemInfo. </param>
        public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value)
        {
            if (value is null)
            {
                throw GetConvertFromException(null);
            }

            var source = value as string;

            if (source is not null)
            {
                object result = Activator.CreateInstance <T>();
                NameValueCollectionHelper.SetNameValueCollection(ref result, NameValueCollectionHelper.Parse(source));
                return(result);
            }

            return(base.ConvertFrom(context, culture, value));
        }