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
- BezierSegment.cs
- ContentDisposition.cs
- TemplatedMailWebEventProvider.cs
- FaultPropagationRecord.cs
- ResourceReferenceKeyNotFoundException.cs
- Pkcs9Attribute.cs
- MailDefinitionBodyFileNameEditor.cs
- SafeLocalMemHandle.cs
- BevelBitmapEffect.cs
- Crypto.cs
- DetailsViewModeEventArgs.cs
- SystemNetworkInterface.cs
- Thread.cs
- BrowserTree.cs
- RuntimeResourceSet.cs
- ViewLoader.cs
- OdbcParameter.cs
- NativeStructs.cs
- LinqMaximalSubtreeNominator.cs
- NamedPipeConnectionPoolSettings.cs
- UseLicense.cs
- CaretElement.cs
- WindowsListViewItem.cs
- PolyQuadraticBezierSegment.cs
- AnnotationComponentManager.cs
- ObjectPropertyMapping.cs
- SmiConnection.cs
- PointCollectionConverter.cs
- hebrewshape.cs
- SapiInterop.cs
- CaseExpr.cs
- CodeLinePragma.cs
- GeneralTransform3DTo2DTo3D.cs
- DataServiceContext.cs
- _UriSyntax.cs
- StreamGeometryContext.cs
- ChannelPoolSettingsElement.cs
- ObjectListCommandCollection.cs
- WorkflowServiceAttributesTypeConverter.cs
- MediaPlayerState.cs
- NoneExcludedImageIndexConverter.cs
- X509Certificate2.cs
- PathData.cs
- SerialPinChanges.cs
- BitmapEffectvisualstate.cs
- Visual3D.cs
- Int16.cs
- GZipUtils.cs
- PropertyChangedEventArgs.cs
- DataGridClipboardCellContent.cs
- CategoryNameCollection.cs
- RemoteWebConfigurationHostServer.cs
- MultitargetingHelpers.cs
- HostExecutionContextManager.cs
- CatalogPartCollection.cs
- COSERVERINFO.cs
- DeobfuscatingStream.cs
- coordinatorscratchpad.cs
- SecurityTokenAttachmentMode.cs
- MemberInfoSerializationHolder.cs
- Quad.cs
- XPathPatternParser.cs
- DataGridPagingPage.cs
- DocumentSchemaValidator.cs
- WebBrowserSiteBase.cs
- RadioButtonAutomationPeer.cs
- CompoundFileDeflateTransform.cs
- _UriSyntax.cs
- XamlVector3DCollectionSerializer.cs
- BooleanSwitch.cs
- ToolBarOverflowPanel.cs
- EntryWrittenEventArgs.cs
- XmlQueryStaticData.cs
- PersonalizationEntry.cs
- ProviderSettings.cs
- TabItemAutomationPeer.cs
- __Filters.cs
- WebPartConnectionsCancelEventArgs.cs
- CategoryAttribute.cs
- Peer.cs
- BufferedGraphicsContext.cs
- ChangeTracker.cs
- ListSortDescription.cs
- NodeCounter.cs
- IImplicitResourceProvider.cs
- CollectionView.cs
- CompositeCollection.cs
- DefaultIfEmptyQueryOperator.cs
- AssemblyBuilder.cs
- XmlSerializerAssemblyAttribute.cs
- SQLDateTimeStorage.cs
- CreateUserWizardStep.cs
- FirstQueryOperator.cs
- SqlNodeAnnotations.cs
- EventSource.cs
- MarginsConverter.cs
- AspNetCompatibilityRequirementsAttribute.cs
- PersonalizationStateInfo.cs
- SelectionItemPattern.cs
- ChtmlPageAdapter.cs