Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- SqlClientWrapperSmiStreamChars.cs
- CompositeScriptReferenceEventArgs.cs
- TouchPoint.cs
- TextServicesHost.cs
- ObjectIDGenerator.cs
- BitVec.cs
- UpnEndpointIdentityExtension.cs
- DesignerProperties.cs
- WebPartEditorCancelVerb.cs
- Mappings.cs
- SQLMembershipProvider.cs
- TextBoxLine.cs
- MultiBinding.cs
- XslTransform.cs
- OdbcDataReader.cs
- TableParagraph.cs
- ExceptionAggregator.cs
- HandlerBase.cs
- DataBinder.cs
- BaseComponentEditor.cs
- SortedList.cs
- CellRelation.cs
- ProfileEventArgs.cs
- AttributeCollection.cs
- Models.cs
- ByteKeyFrameCollection.cs
- XmlValidatingReaderImpl.cs
- XmlJsonWriter.cs
- ServiceOperation.cs
- Schema.cs
- RoleManagerEventArgs.cs
- TreeViewItemAutomationPeer.cs
- ContentElement.cs
- XmlSchemaSimpleContent.cs
- ObjectDataSourceDesigner.cs
- OleDbCommand.cs
- PrintPageEvent.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- ColorTranslator.cs
- PropertyEmitterBase.cs
- PropertyReference.cs
- Handle.cs
- SoapTypeAttribute.cs
- RoleGroupCollection.cs
- CharAnimationBase.cs
- ToolStripSplitButton.cs
- DataGridViewButtonColumn.cs
- ToolStripDropDownClosedEventArgs.cs
- OutputCacheSection.cs
- WebServicesInteroperability.cs
- TemplatePartAttribute.cs
- LinkTarget.cs
- OdbcDataAdapter.cs
- Collection.cs
- TypeUnloadedException.cs
- SerializationEventsCache.cs
- SQLBytes.cs
- TcpConnectionPoolSettingsElement.cs
- PackageDigitalSignatureManager.cs
- DbParameterHelper.cs
- GuidConverter.cs
- SystemWebCachingSectionGroup.cs
- XPathSelfQuery.cs
- dataprotectionpermissionattribute.cs
- PropertyOverridesTypeEditor.cs
- FormsAuthentication.cs
- ItemMap.cs
- DataControlCommands.cs
- TailCallAnalyzer.cs
- SingleObjectCollection.cs
- Deflater.cs
- Select.cs
- DependencyObjectType.cs
- PseudoWebRequest.cs
- LinearKeyFrames.cs
- Point3D.cs
- EncryptedKey.cs
- DeploymentExceptionMapper.cs
- HandlerFactoryWrapper.cs
- log.cs
- XmlAttributeAttribute.cs
- UriTemplateMatch.cs
- AnnotationComponentChooser.cs
- IImplicitResourceProvider.cs
- DataGridViewColumnEventArgs.cs
- WebPartMinimizeVerb.cs
- SqlDataSourceQuery.cs
- GradientStop.cs
- Visual3D.cs
- DynamicRenderer.cs
- Highlights.cs
- wgx_render.cs
- SafePEFileHandle.cs
- AppliedDeviceFiltersEditor.cs
- Switch.cs
- InstanceCollisionException.cs
- SurrogateEncoder.cs
- AdornerLayer.cs
- HMACMD5.cs
- QueryBranchOp.cs