Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Configuration / System / Configuration / RegexStringValidator.cs / 1 / RegexStringValidator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Text.RegularExpressions; namespace System.Configuration { public class RegexStringValidator : ConfigurationValidatorBase { private string _expression; private Regex _regex; public RegexStringValidator(string regex) { if (string.IsNullOrEmpty(regex)) { throw ExceptionUtil.ParameterNullOrEmpty("regex"); } _expression = regex; _regex = new Regex(regex, RegexOptions.Compiled); } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); if (value == null) { return; } Match match = _regex.Match((string)value); if (!match.Success) { throw new ArgumentException(SR.GetString(SR.Regex_validator_error, _expression)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Text.RegularExpressions; namespace System.Configuration { public class RegexStringValidator : ConfigurationValidatorBase { private string _expression; private Regex _regex; public RegexStringValidator(string regex) { if (string.IsNullOrEmpty(regex)) { throw ExceptionUtil.ParameterNullOrEmpty("regex"); } _expression = regex; _regex = new Regex(regex, RegexOptions.Compiled); } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); if (value == null) { return; } Match match = _regex.Match((string)value); if (!match.Success) { throw new ArgumentException(SR.GetString(SR.Regex_validator_error, _expression)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _NtlmClient.cs
- WebEventTraceProvider.cs
- HighlightVisual.cs
- ExtendedTransformFactory.cs
- FrameworkElementFactory.cs
- BindingRestrictions.cs
- ArgumentsParser.cs
- FillErrorEventArgs.cs
- LOSFormatter.cs
- XmlMtomReader.cs
- DictionaryEntry.cs
- UserNameSecurityToken.cs
- Quad.cs
- MethodExpression.cs
- DataGridColumnsPage.cs
- DrawingImage.cs
- AccessDataSource.cs
- DocumentGridContextMenu.cs
- Process.cs
- RelatedImageListAttribute.cs
- XamlSerializerUtil.cs
- FontStyleConverter.cs
- PatternMatchRules.cs
- EdmTypeAttribute.cs
- CheckedPointers.cs
- PropertyOverridesTypeEditor.cs
- DependencyObjectProvider.cs
- HtmlButton.cs
- ToolboxItemFilterAttribute.cs
- ServiceNameElementCollection.cs
- SHA512.cs
- ConfigurationSectionCollection.cs
- EdmRelationshipRoleAttribute.cs
- PointAnimationUsingKeyFrames.cs
- TypeKeyValue.cs
- ConvertersCollection.cs
- Image.cs
- CompatibleIComparer.cs
- OrthographicCamera.cs
- PrimitiveSchema.cs
- DbDataReader.cs
- ObfuscationAttribute.cs
- ping.cs
- DrawListViewItemEventArgs.cs
- SerTrace.cs
- MetaModel.cs
- DecoderBestFitFallback.cs
- NegotiateStream.cs
- ReadWriteSpinLock.cs
- TableHeaderCell.cs
- ScrollPattern.cs
- WindowsGraphics.cs
- DrawingBrush.cs
- XmlElementAttributes.cs
- PasswordBoxAutomationPeer.cs
- PropertyDescriptorGridEntry.cs
- CounterCreationData.cs
- CryptoApi.cs
- AnimationLayer.cs
- PropertyIDSet.cs
- RemoteWebConfigurationHost.cs
- Point3DCollection.cs
- ResourceDictionary.cs
- PropertyChangedEventArgs.cs
- SplineQuaternionKeyFrame.cs
- Span.cs
- ContainerTracking.cs
- IndexOutOfRangeException.cs
- TextTreeUndoUnit.cs
- Utilities.cs
- ConfigXmlElement.cs
- EntityModelSchemaGenerator.cs
- SamlAssertionKeyIdentifierClause.cs
- InvalidMessageContractException.cs
- ToolTip.cs
- MonitoringDescriptionAttribute.cs
- HtmlInputSubmit.cs
- ResizeGrip.cs
- GenericIdentity.cs
- MutexSecurity.cs
- XmlConverter.cs
- BitmapEffectGroup.cs
- StandardTransformFactory.cs
- StrongTypingException.cs
- CacheAxisQuery.cs
- SqlConnectionStringBuilder.cs
- DataSourceConverter.cs
- SqlDependencyUtils.cs
- CapabilitiesPattern.cs
- EntityConnectionStringBuilder.cs
- OleServicesContext.cs
- XmlSchemaImport.cs
- WindowsAltTab.cs
- PerspectiveCamera.cs
- EllipseGeometry.cs
- UIElement3D.cs
- TraceShell.cs
- Button.cs
- TimeZoneNotFoundException.cs
- TakeOrSkipQueryOperator.cs