ConvertFromString() приватный Метод

private ConvertFromString ( string value ) : Object
value string
Результат Object
Пример #1
0
 internal void SetStringValue(string value)
 {
     val = property.ConvertFromString(value);
     if (!object.Equals(val, DefaultValue))
     {
         origin = PropertyValueOrigin.SetHere;
     }
 }
Пример #2
0
        void ValidateValue(ConfigurationProperty p, string value)
        {
            ConfigurationValidatorBase validator;

            if (p == null || (validator = p.Validator) == null)
            {
                return;
            }

            if (!validator.CanValidate(p.Type))
            {
                throw new ConfigurationErrorsException(
                          String.Format("Validator does not support type {0}", p.Type));
            }
            validator.Validate(p.ConvertFromString(value));
        }
 private object DeserializePropertyValue(ConfigurationProperty prop, XmlReader reader)
 {
     string str = reader.Value;
     object obj2 = null;
     try
     {
         obj2 = prop.ConvertFromString(str);
         prop.Validate(obj2);
     }
     catch (ConfigurationException exception)
     {
         if (string.IsNullOrEmpty(exception.Filename))
         {
             exception = new ConfigurationErrorsException(exception.Message, reader);
         }
         obj2 = new InvalidPropValue(str, exception);
     }
     catch
     {
     }
     return obj2;
 }
        private object DeserializePropertyValue(ConfigurationProperty prop, XmlReader reader) {
            Debug.Assert(prop != null, "prop != null");
            Debug.Assert(reader != null, "reader != null");

            // By default we try to load (i.e. parse/validate ) all properties
            // If a property value is invalid ( cannot be parsed or is not valid ) we will keep the value
            // as string ( from the xml ) and will write it out unchanged if needed
            // If the property value is needed by users the actuall exception will be thrown

            string xmlValue = reader.Value;
            object propertyValue = null;

            try {
                propertyValue = prop.ConvertFromString(xmlValue);

                // Validate the loaded and converted value
                prop.Validate(propertyValue);
            }
            catch (ConfigurationException ce) {
                // If the error is incomplete - complete it :)
                if (string.IsNullOrEmpty(ce.Filename)) {
                    ce = new ConfigurationErrorsException(ce.Message, reader);
                }

                // Cannot parse/validate the value. Keep it as string
                propertyValue = new InvalidPropValue(xmlValue, ce);
            }
            catch {
                // If this is an exception related to the parsing/validating the 
                // value ConfigurationErrorsException should be thrown instead.
                // If not - the exception is ok to surface out of here
                Debug.Fail("Unknown exception type thrown");
            }

            return propertyValue;
        }
Пример #5
0
		void ValidateValue (ConfigurationProperty p, string value)
		{
			ConfigurationValidatorBase validator;
			if (p == null || (validator = p.Validator) == null)
				return;
			
			if (!validator.CanValidate (p.Type))
				throw new ConfigurationErrorsException (
					String.Format ("Validator does not support type {0}", p.Type));
			validator.Validate (p.ConvertFromString (value));
		}
Пример #6
0
 private object DeserializePropertyValue(ConfigurationProperty prop, XmlReader reader)
 {
     string str = reader.Value;
       object obj = (object) null;
       try
       {
     obj = prop.ConvertFromString(str);
     prop.Validate(obj);
       }
       catch (ConfigurationException ex)
       {
     ConfigurationException error = ex;
     if (string.IsNullOrEmpty(error.Filename))
       error = (ConfigurationException) new ConfigurationErrorsException(error.Message, reader);
     obj = (object) new InvalidPropValue(str, error);
       }
       catch
       {
       }
       return obj;
 }