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
- Ray3DHitTestResult.cs
- DataGridViewSelectedRowCollection.cs
- FileVersion.cs
- BitmapSizeOptions.cs
- SplineQuaternionKeyFrame.cs
- Transform3DGroup.cs
- ReversePositionQuery.cs
- TargetException.cs
- SetUserLanguageRequest.cs
- PartitionerStatic.cs
- PerspectiveCamera.cs
- HttpWriter.cs
- Number.cs
- CmsInterop.cs
- HttpGetProtocolImporter.cs
- SHA256Managed.cs
- InputScopeNameConverter.cs
- DBCommand.cs
- Frame.cs
- ExtensionFile.cs
- DiagnosticTrace.cs
- BufferedGraphicsContext.cs
- WebHttpSecurityModeHelper.cs
- PropertyChangeTracker.cs
- TcpAppDomainProtocolHandler.cs
- SecurityTokenParametersEnumerable.cs
- ProfilePropertySettingsCollection.cs
- EntityType.cs
- ValidationService.cs
- COM2PictureConverter.cs
- RepeaterItemEventArgs.cs
- MailMessageEventArgs.cs
- ColumnResult.cs
- XmlNullResolver.cs
- XmlSerializationReader.cs
- XpsFont.cs
- NetPeerTcpBindingCollectionElement.cs
- AtlasWeb.Designer.cs
- MailSettingsSection.cs
- Point3DCollection.cs
- ReaderWriterLock.cs
- PropertyChangingEventArgs.cs
- BindingSource.cs
- CacheSection.cs
- _SslState.cs
- TimeEnumHelper.cs
- SocketException.cs
- SettingsPropertyNotFoundException.cs
- WorkflowInvoker.cs
- DbConnectionPoolIdentity.cs
- OperatingSystem.cs
- QilXmlReader.cs
- COM2ColorConverter.cs
- DataGridViewColumnHeaderCell.cs
- FixedHyperLink.cs
- ReadOnlyNameValueCollection.cs
- RadioButtonFlatAdapter.cs
- Stackframe.cs
- wgx_sdk_version.cs
- CapabilitiesAssignment.cs
- Span.cs
- KeyTimeConverter.cs
- TextRangeProviderWrapper.cs
- TimeoutHelper.cs
- TableTextElementCollectionInternal.cs
- PropertyMetadata.cs
- DesignerActionMethodItem.cs
- WebConfigurationHostFileChange.cs
- SettingsPropertyWrongTypeException.cs
- ErrorTableItemStyle.cs
- AdornerLayer.cs
- milrender.cs
- XslAstAnalyzer.cs
- X509LogoTypeExtension.cs
- Underline.cs
- ExpressionsCollectionConverter.cs
- ChangeConflicts.cs
- MSAANativeProvider.cs
- TypeConverterHelper.cs
- WebPartConnection.cs
- XmlUnspecifiedAttribute.cs
- CodeTryCatchFinallyStatement.cs
- WsiProfilesElementCollection.cs
- XmlSerializerVersionAttribute.cs
- RegistryHandle.cs
- ProvideValueServiceProvider.cs
- ACE.cs
- CodeDomConfigurationHandler.cs
- Viewport3DVisual.cs
- BevelBitmapEffect.cs
- StylusButtonEventArgs.cs
- DataTableClearEvent.cs
- TransactionScope.cs
- WhitespaceSignificantCollectionAttribute.cs
- MsmqInputChannelListener.cs
- ValidationHelper.cs
- MediaSystem.cs
- Native.cs
- CollectionExtensions.cs
- PageContentAsyncResult.cs