System.ComponentModel.TypeConverter.ConvertFromInvariantString C# (CSharp) Method

ConvertFromInvariantString() public method

public ConvertFromInvariantString ( ITypeDescriptorContext context, string text ) : object
context ITypeDescriptorContext
text string
return object
        public object ConvertFromInvariantString(ITypeDescriptorContext context, string text) {
            return ConvertFromString(context, CultureInfo.InvariantCulture, text);
        }

Same methods

TypeConverter::ConvertFromInvariantString ( string text ) : object

Usage Example

        private static bool InnerConvertObjectToType(object obj, Type type, bool throwOnError,
                                                     out object convertedObject)
        {
            Type originalType = obj.GetType();
            OriginalTypeConverter converter = TypeDescriptor.GetConverter(type);

            if (converter.CanConvertFrom(originalType))
            {
                try
                {
                    convertedObject = converter.ConvertFrom(null, CultureInfo.InvariantCulture, obj);
                    return(true);
                }
                catch
                {
                    if (throwOnError)
                    {
                        throw;
                    }

                    convertedObject = null;
                    return(false);
                }
            }

            if (converter.CanConvertFrom(typeof(string)) && !(obj is DateTime))
            {
                try
                {
                    string text = TypeDescriptor.GetConverter(originalType).ConvertToInvariantString(obj);

                    convertedObject = converter.ConvertFromInvariantString(text);
                    return(true);
                }
                catch
                {
                    if (throwOnError)
                    {
                        throw;
                    }

                    convertedObject = null;
                    return(false);
                }
            }

            if (type.IsInstanceOfType(obj))
            {
                convertedObject = obj;
                return(true);
            }

            if (throwOnError)
            {
                throw new InvalidOperationException();
            }

            convertedObject = null;
            return(false);
        }
All Usage Examples Of System.ComponentModel.TypeConverter::ConvertFromInvariantString