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
- XPathAncestorQuery.cs
- SafeRightsManagementHandle.cs
- WebServiceHostFactory.cs
- ConditionalWeakTable.cs
- AsymmetricSignatureDeformatter.cs
- WebReference.cs
- TypeUtil.cs
- SqlDataSourceView.cs
- DataGridViewElement.cs
- DataGridViewAddColumnDialog.cs
- GeometryGroup.cs
- BooleanAnimationBase.cs
- MappableObjectManager.cs
- ProfileGroupSettings.cs
- TextTreeUndoUnit.cs
- OdbcDataAdapter.cs
- StrongNameKeyPair.cs
- ReflectionTypeLoadException.cs
- Pair.cs
- SingleTagSectionHandler.cs
- AutoCompleteStringCollection.cs
- ListViewInsertionMark.cs
- CommonDialog.cs
- MissingFieldException.cs
- SelectionBorderGlyph.cs
- BidOverLoads.cs
- _TimerThread.cs
- MimeMapping.cs
- input.cs
- WebPartsPersonalizationAuthorization.cs
- SchemaImporter.cs
- BamlBinaryWriter.cs
- ResourcesBuildProvider.cs
- DataGridColumnCollectionEditor.cs
- ColumnResult.cs
- PageCopyCount.cs
- Padding.cs
- MessageQueueTransaction.cs
- MetadataWorkspace.cs
- ExtentCqlBlock.cs
- DesignerSerializerAttribute.cs
- WindowCollection.cs
- MimeTypeMapper.cs
- PathFigureCollectionConverter.cs
- ClientSponsor.cs
- BuildProvider.cs
- DataPager.cs
- ReturnValue.cs
- SamlConditions.cs
- BaseProcessor.cs
- Predicate.cs
- ConfigXmlWhitespace.cs
- WSSecurityPolicy.cs
- ListViewCommandEventArgs.cs
- RoutedPropertyChangedEventArgs.cs
- ToReply.cs
- cache.cs
- CancellationTokenSource.cs
- LayoutTable.cs
- XmlArrayItemAttributes.cs
- RsaSecurityToken.cs
- _ListenerResponseStream.cs
- StrongNamePublicKeyBlob.cs
- XmlILAnnotation.cs
- SqlNodeTypeOperators.cs
- ReachVisualSerializerAsync.cs
- GroupBoxAutomationPeer.cs
- TableLayoutPanelDesigner.cs
- RankException.cs
- CustomLineCap.cs
- ContentElement.cs
- SoapInteropTypes.cs
- FileInfo.cs
- TouchEventArgs.cs
- CompilerGeneratedAttribute.cs
- EventLogEntryCollection.cs
- Region.cs
- CodeParameterDeclarationExpression.cs
- CatalogPartCollection.cs
- namescope.cs
- DataGridViewCellValidatingEventArgs.cs
- ClipboardProcessor.cs
- PrinterResolution.cs
- COM2FontConverter.cs
- HostingEnvironmentWrapper.cs
- FileLevelControlBuilderAttribute.cs
- ValueSerializerAttribute.cs
- RoutingExtension.cs
- CapabilitiesState.cs
- MethodExpr.cs
- BaseAsyncResult.cs
- RijndaelManaged.cs
- DateTimeFormat.cs
- ErrorTableItemStyle.cs
- ValueExpressions.cs
- PropVariant.cs
- RemoteWebConfigurationHostStream.cs
- InvokeProviderWrapper.cs
- QualificationDataItem.cs
- XmlSchemaProviderAttribute.cs