当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationProperty.Validate方法代码示例

本文整理汇总了C#中System.Configuration.ConfigurationProperty.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationProperty.Validate方法的具体用法?C# ConfigurationProperty.Validate怎么用?C# ConfigurationProperty.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Configuration.ConfigurationProperty的用法示例。


在下文中一共展示了ConfigurationProperty.Validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeserializePropertyValue

 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:ConfigurationElement.cs

示例2: SetPropertyValue

 protected void SetPropertyValue(ConfigurationProperty prop, object value, bool ignoreLocks)
 {
     if (this.IsReadOnly())
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_read_only"));
     }
     if (!ignoreLocks && (((((this._lockedAllExceptAttributesList != null) && this._lockedAllExceptAttributesList.HasParentElements) && !this._lockedAllExceptAttributesList.DefinedInParent(prop.Name)) || ((this._lockedAttributesList != null) && (this._lockedAttributesList.DefinedInParent(prop.Name) || this._lockedAttributesList.DefinedInParent("*")))) || (((this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) && ((this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default))))
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { prop.Name }));
     }
     this._bModified = true;
     if (value != null)
     {
         prop.Validate(value);
     }
     this._values[prop.Name] = (value != null) ? value : s_nullPropertyValue;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:ConfigurationElement.cs

示例3: SetPropertyValue

        protected void SetPropertyValue(ConfigurationProperty prop, object value, bool ignoreLocks) {
            if (IsReadOnly()) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
            }

            if ((ignoreLocks == false) && 
                ((_lockedAllExceptAttributesList != null && _lockedAllExceptAttributesList.HasParentElements && !_lockedAllExceptAttributesList.DefinedInParent(prop.Name)) ||
                    (_lockedAttributesList != null && (_lockedAttributesList.DefinedInParent(prop.Name) || _lockedAttributesList.DefinedInParent(LockAll))) ||
                    ((_fItemLocked & ConfigurationValueFlags.Locked) != 0) &&
                    (_fItemLocked & ConfigurationValueFlags.Inherited) != 0)) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_attribute_locked, prop.Name));
            }

            _bModified = true;

            // Run the new value through the validator to make sure its ok to store it
            if (value != null) {
                prop.Validate(value);
            }

            _values[prop.Name] = (value != null) ? value : s_nullPropertyValue;
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:22,代码来源:configurationelement.cs

示例4: DeserializePropertyValue

        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;
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:36,代码来源:configurationelement.cs

示例5: SetPropertyValue

		protected void SetPropertyValue (ConfigurationProperty prop, object value, bool ignoreLocks)
		{
			try {
				if (value != null) {
					/* XXX all i know for certain is that Validation happens here */
					prop.Validate (value);

					/* XXX presumably the actual setting of the
					 * property happens here instead of in the
					 * set_Item code below, but that would mean
					 * the Value needs to be stuffed in the
					 * property, not the propertyinfo (or else the
					 * property needs a ref to the property info
					 * to correctly set the value). */
				}
			}
			catch (Exception e) {
				throw new ConfigurationErrorsException (String.Format ("The value for the property '{0}' on type {1} is not valid.", prop.Name, this.ElementInformation.Type), e);
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:20,代码来源:ConfigurationElement.cs

示例6: DeserializePropertyValue

 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;
 }
开发者ID:wcpro,项目名称:iEnvoke,代码行数:21,代码来源:ConfigurationElement.cs


注:本文中的System.Configuration.ConfigurationProperty.Validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。