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
- MailAddressCollection.cs
- GeometryGroup.cs
- MethodBody.cs
- TypefaceCollection.cs
- TextRunTypographyProperties.cs
- TextEvent.cs
- cookiecollection.cs
- SurrogateEncoder.cs
- TableDetailsRow.cs
- SharedPerformanceCounter.cs
- ObfuscateAssemblyAttribute.cs
- CapabilitiesRule.cs
- Metafile.cs
- NetCodeGroup.cs
- RecognitionResult.cs
- AnnotationStore.cs
- smtppermission.cs
- UIElement.cs
- AdjustableArrowCap.cs
- CodeCatchClause.cs
- MULTI_QI.cs
- StatusBarAutomationPeer.cs
- ListViewInsertionMark.cs
- TrackingMemoryStream.cs
- XPathNodeHelper.cs
- TypeConverterHelper.cs
- CacheSection.cs
- CodeTypeDeclarationCollection.cs
- ConfigurationElementProperty.cs
- BackEase.cs
- CreateBookmarkScope.cs
- DrawingAttributes.cs
- Duration.cs
- CheckBoxFlatAdapter.cs
- ADMembershipUser.cs
- PropertyRecord.cs
- Msec.cs
- HebrewNumber.cs
- TableItemStyle.cs
- InputBuffer.cs
- ProcessThreadDesigner.cs
- ReliableOutputConnection.cs
- RadioButtonStandardAdapter.cs
- DecoderFallback.cs
- DecoderBestFitFallback.cs
- DebuggerAttributes.cs
- WindowsContainer.cs
- PathSegmentCollection.cs
- DesignerLoader.cs
- GetUserPreferenceRequest.cs
- Literal.cs
- SecurityTokenParameters.cs
- TextOnlyOutput.cs
- TextEmbeddedObject.cs
- XmlDocument.cs
- SymbolEqualComparer.cs
- ContractCodeDomInfo.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ILGenerator.cs
- SqlTriggerAttribute.cs
- WebPartConnectVerb.cs
- OneWayChannelFactory.cs
- _NegoState.cs
- wgx_render.cs
- MarshalByRefObject.cs
- UntrustedRecipientException.cs
- CustomError.cs
- XmlNode.cs
- StructuredCompositeActivityDesigner.cs
- PropertyGridView.cs
- InstanceDataCollection.cs
- UnsafeNetInfoNativeMethods.cs
- WindowsListViewItem.cs
- TabletCollection.cs
- ResponseStream.cs
- LinkLabel.cs
- NameValueConfigurationElement.cs
- DataAdapter.cs
- assertwrapper.cs
- InkCanvasSelection.cs
- QueryCacheManager.cs
- ListDictionaryInternal.cs
- IIS7WorkerRequest.cs
- PrintPreviewGraphics.cs
- Stroke.cs
- Rect3D.cs
- DrawListViewColumnHeaderEventArgs.cs
- UnmanagedMarshal.cs
- PageHandlerFactory.cs
- EventLogLink.cs
- SQLMembershipProvider.cs
- sapiproxy.cs
- DataGridViewRowEventArgs.cs
- AppDomainFactory.cs
- DataFormats.cs
- MetafileHeader.cs
- StylusPoint.cs
- ModelTreeEnumerator.cs
- StorageEndPropertyMapping.cs
- TypefaceMetricsCache.cs