Example #1
0
        /// <summary>
        /// Attempts to convert to a CacheMode from the given object.
        /// </summary>
        /// <returns>
        /// The CacheMode 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 CacheMode.
        /// </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 CacheMode. </param>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string source)
            {
                return(CacheMode.Parse(source));
            }

            throw GetConvertFromException(value);
        }
Example #2
0
 /// <summary>
 /// Converts a string into a CacheMode.
 /// </summary>
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     if (value != null)
     {
         return(CacheMode.Parse(value));
     }
     else
     {
         return(base.ConvertFromString(value, context));
     }
 }