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
- ErasingStroke.cs
- DBAsyncResult.cs
- ViewManager.cs
- OperationFormatStyle.cs
- ProcessHostServerConfig.cs
- BindingManagerDataErrorEventArgs.cs
- PrivilegeNotHeldException.cs
- XslAst.cs
- InstanceLockLostException.cs
- PingOptions.cs
- TreeViewHitTestInfo.cs
- UnknownBitmapEncoder.cs
- CompatibleComparer.cs
- ColorDialog.cs
- UniqueEventHelper.cs
- UnsafeNativeMethodsCLR.cs
- Vector3DAnimationBase.cs
- FormViewDeletedEventArgs.cs
- JsonSerializer.cs
- DatagridviewDisplayedBandsData.cs
- DataColumnSelectionConverter.cs
- XmlReflectionImporter.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- TreeViewEvent.cs
- PropertyValueChangedEvent.cs
- TimeoutException.cs
- TypeElementCollection.cs
- DocumentSchemaValidator.cs
- Pair.cs
- QilTypeChecker.cs
- HttpPostProtocolImporter.cs
- LayoutEngine.cs
- WebPartConnectionsCancelEventArgs.cs
- CheckBoxStandardAdapter.cs
- CaseInsensitiveOrdinalStringComparer.cs
- FolderNameEditor.cs
- MetadataArtifactLoaderFile.cs
- PageThemeParser.cs
- DataGridViewColumnStateChangedEventArgs.cs
- AudioSignalProblemOccurredEventArgs.cs
- ColumnBinding.cs
- ComplexLine.cs
- Context.cs
- LookupBindingPropertiesAttribute.cs
- SimpleType.cs
- Model3D.cs
- WeakEventManager.cs
- XappLauncher.cs
- ScriptingAuthenticationServiceSection.cs
- CodeNamespaceCollection.cs
- BinaryFormatter.cs
- SwitchAttribute.cs
- UrlPropertyAttribute.cs
- SamlSubject.cs
- RC2.cs
- BorderGapMaskConverter.cs
- XamlWrappingReader.cs
- BitmapEffectGeneralTransform.cs
- FileReservationCollection.cs
- AnyAllSearchOperator.cs
- CollectionExtensions.cs
- WebPartUtil.cs
- SqlDependency.cs
- MonitorWrapper.cs
- TypeBuilder.cs
- Journal.cs
- login.cs
- Vector3dCollection.cs
- ScrollPattern.cs
- LinearGradientBrush.cs
- DataTableMappingCollection.cs
- FixedPageProcessor.cs
- TargetParameterCountException.cs
- CallSiteBinder.cs
- ObjectCache.cs
- DataSourceCache.cs
- ClientSponsor.cs
- WebFormDesignerActionService.cs
- BooleanAnimationBase.cs
- WebServiceTypeData.cs
- DataGridViewTopRowAccessibleObject.cs
- ErrorRuntimeConfig.cs
- WorkflowViewElement.cs
- LessThanOrEqual.cs
- PrintPreviewControl.cs
- ReservationCollection.cs
- SoapCodeExporter.cs
- DataProviderNameConverter.cs
- MarkedHighlightComponent.cs
- TreeView.cs
- ProviderConnectionPointCollection.cs
- Selector.cs
- WeakEventTable.cs
- UnsafeNativeMethods.cs
- BindingGroup.cs
- LabelDesigner.cs
- ActivityAction.cs
- StretchValidation.cs
- SortableBindingList.cs
- MsmqActivation.cs