Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / RegexStringValidator.cs / 1305376 / 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
- DelimitedListTraceListener.cs
- AppSettingsReader.cs
- PolicyFactory.cs
- DataBindEngine.cs
- Slider.cs
- TextEffectResolver.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- GroupQuery.cs
- Annotation.cs
- Int32CollectionConverter.cs
- AsyncResult.cs
- SqlClientFactory.cs
- CodeMemberMethod.cs
- Roles.cs
- ByteAnimationUsingKeyFrames.cs
- LazyTextWriterCreator.cs
- COM2PropertyBuilderUITypeEditor.cs
- SqlNodeAnnotation.cs
- HttpSocketManager.cs
- CodeLabeledStatement.cs
- Transaction.cs
- HorizontalAlignConverter.cs
- InvalidAsynchronousStateException.cs
- SqlDataSourceCommandEventArgs.cs
- OdbcDataAdapter.cs
- InputBindingCollection.cs
- AllMembershipCondition.cs
- ContentElement.cs
- DataSourceGeneratorException.cs
- StorageEntitySetMapping.cs
- StyleBamlTreeBuilder.cs
- ConstructorNeedsTagAttribute.cs
- TCPClient.cs
- SqlUdtInfo.cs
- Polyline.cs
- WebSysDescriptionAttribute.cs
- ActionItem.cs
- TextTabProperties.cs
- BooleanFacetDescriptionElement.cs
- MenuRendererClassic.cs
- WebPartConnectionsCloseVerb.cs
- EncryptedData.cs
- BitmapEffectInputData.cs
- ObjectIDGenerator.cs
- ApplicationException.cs
- KeyPressEvent.cs
- AuthenticationModulesSection.cs
- LinqDataSourceContextData.cs
- DataListItemEventArgs.cs
- AnyReturnReader.cs
- TemplateField.cs
- NativeStructs.cs
- webbrowsersite.cs
- CodeTypeParameter.cs
- EmptyStringExpandableObjectConverter.cs
- HeaderedContentControl.cs
- WebScriptClientGenerator.cs
- XPathException.cs
- DbConnectionFactory.cs
- Stackframe.cs
- XmlAttributeCache.cs
- BooleanFunctions.cs
- SupportingTokenParameters.cs
- Deserializer.cs
- DataGridViewLinkCell.cs
- FontConverter.cs
- FilteredDataSetHelper.cs
- SemanticBasicElement.cs
- FlowDocumentReaderAutomationPeer.cs
- WSFederationHttpBinding.cs
- IRCollection.cs
- WizardPanel.cs
- StylusButton.cs
- PrimitiveSchema.cs
- ExtendedPropertyDescriptor.cs
- SettingsProperty.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- LayeredChannelFactory.cs
- ServiceModelSecurityTokenRequirement.cs
- ClientBuildManager.cs
- HMACMD5.cs
- QueuePathEditor.cs
- GeneralTransformGroup.cs
- TextBounds.cs
- TextLineBreak.cs
- OdbcParameterCollection.cs
- TypeUsage.cs
- CompoundFileStorageReference.cs
- WebAdminConfigurationHelper.cs
- ValuePatternIdentifiers.cs
- ZoneButton.cs
- StylusPointPropertyUnit.cs
- WriteFileContext.cs
- ChangeToolStripParentVerb.cs
- ColorTransformHelper.cs
- RowCache.cs
- InstanceHandle.cs
- ObjectDataSource.cs
- ExpressionPrefixAttribute.cs
- ResourcePermissionBase.cs