Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- WebPartUserCapability.cs
- GeometryGroup.cs
- StringConverter.cs
- EmptyElement.cs
- XmlSchemaInferenceException.cs
- DataGridToolTip.cs
- GlyphsSerializer.cs
- CompressStream.cs
- EventProvider.cs
- XmlFormatExtensionAttribute.cs
- XmlArrayAttribute.cs
- ConsumerConnectionPointCollection.cs
- storagemappingitemcollection.viewdictionary.cs
- NullableBoolConverter.cs
- DataGridColumn.cs
- Content.cs
- OdbcDataAdapter.cs
- WebZone.cs
- TimeoutException.cs
- DependencyPropertyKind.cs
- HyperLinkColumn.cs
- StateManagedCollection.cs
- TextServicesContext.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- latinshape.cs
- Win32Exception.cs
- CheckBox.cs
- ShapeTypeface.cs
- PropertyReference.cs
- TransformerInfoCollection.cs
- Types.cs
- ServiceModelInstallComponent.cs
- MachineKeySection.cs
- ColumnPropertiesGroup.cs
- BaseResourcesBuildProvider.cs
- RegistryKey.cs
- PathSegmentCollection.cs
- ObfuscateAssemblyAttribute.cs
- SmiConnection.cs
- UserUseLicenseDictionaryLoader.cs
- SqlCacheDependency.cs
- DropShadowEffect.cs
- BufferManager.cs
- Atom10FeedFormatter.cs
- LeaseManager.cs
- XmlLanguageConverter.cs
- Image.cs
- RoleGroupCollectionEditor.cs
- AbstractExpressions.cs
- EvidenceBase.cs
- UserPreferenceChangingEventArgs.cs
- StrokeRenderer.cs
- RegexMatch.cs
- CachedPathData.cs
- DateTimeFormat.cs
- XmlElement.cs
- Relationship.cs
- SqlWriter.cs
- TreeNodeCollectionEditorDialog.cs
- DataGridRelationshipRow.cs
- SafePointer.cs
- StringConverter.cs
- datacache.cs
- SchemaImporter.cs
- QilGeneratorEnv.cs
- StructuredTypeEmitter.cs
- SqlConnectionHelper.cs
- EntityDataReader.cs
- RegistryKey.cs
- BamlRecordReader.cs
- FtpRequestCacheValidator.cs
- ProxyWebPart.cs
- XmlSchemas.cs
- LocationReferenceValue.cs
- BitmapPalettes.cs
- XPathAxisIterator.cs
- XdrBuilder.cs
- InputLanguageSource.cs
- SymbolUsageManager.cs
- GridSplitter.cs
- ListBoxItemAutomationPeer.cs
- SelectionManager.cs
- Condition.cs
- SubstitutionResponseElement.cs
- WebPartConnectionsCancelEventArgs.cs
- ToolStripInSituService.cs
- CacheMemory.cs
- VBIdentifierDesigner.xaml.cs
- WebPartVerbCollection.cs
- SiteMapNodeItem.cs
- FtpCachePolicyElement.cs
- StreamFormatter.cs
- ScrollProperties.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ExpandedWrapper.cs
- XmlRawWriter.cs
- TimeoutHelper.cs
- SignedPkcs7.cs
- IdentityElement.cs
- ClientRoleProvider.cs