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
- RectangleHotSpot.cs
- storagemappingitemcollection.viewdictionary.cs
- ConsoleKeyInfo.cs
- ReflectPropertyDescriptor.cs
- PriorityQueue.cs
- SizeLimitedCache.cs
- Preprocessor.cs
- EpmHelper.cs
- SqlResolver.cs
- IsolatedStorageException.cs
- SmtpDigestAuthenticationModule.cs
- ContainerControl.cs
- MouseGestureConverter.cs
- FilteredReadOnlyMetadataCollection.cs
- EncoderParameters.cs
- ZeroOpNode.cs
- ConfigsHelper.cs
- SID.cs
- FilePrompt.cs
- XmlIterators.cs
- WebPartAddingEventArgs.cs
- Control.cs
- RegexNode.cs
- Buffer.cs
- Interlocked.cs
- SqlDataSourceSelectingEventArgs.cs
- WaitForChangedResult.cs
- PropertyGroupDescription.cs
- COM2ComponentEditor.cs
- DialogResultConverter.cs
- ReturnEventArgs.cs
- InkCanvasFeedbackAdorner.cs
- ApplicationInterop.cs
- assertwrapper.cs
- GenericIdentity.cs
- DictionarySectionHandler.cs
- InternalControlCollection.cs
- ThreadStaticAttribute.cs
- Regex.cs
- ToolStripGrip.cs
- MappingModelBuildProvider.cs
- DataGridTextBoxColumn.cs
- IdentityModelStringsVersion1.cs
- XPathDocument.cs
- ErrorFormatter.cs
- CreateInstanceBinder.cs
- BlockUIContainer.cs
- DirectoryNotFoundException.cs
- ViewBase.cs
- ToolBarButtonClickEvent.cs
- ViewStateModeByIdAttribute.cs
- WindowsScroll.cs
- WebPartManagerInternals.cs
- AxWrapperGen.cs
- DrawingGroupDrawingContext.cs
- TableLayoutPanel.cs
- TablePattern.cs
- errorpatternmatcher.cs
- SerializationIncompleteException.cs
- PersistChildrenAttribute.cs
- PingReply.cs
- VirtualPathUtility.cs
- JoinTreeNode.cs
- BrowserDefinition.cs
- LogPolicy.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- Slider.cs
- DataPager.cs
- SessionSwitchEventArgs.cs
- UnsafeNativeMethods.cs
- CellQuery.cs
- PatternMatcher.cs
- Vector.cs
- SctClaimSerializer.cs
- HtmlShimManager.cs
- mactripleDES.cs
- FileVersionInfo.cs
- ForceCopyBuildProvider.cs
- Ref.cs
- XmlReader.cs
- ScrollChrome.cs
- RadialGradientBrush.cs
- IndexingContentUnit.cs
- DefaultShape.cs
- XmlSchemaDocumentation.cs
- AnimationClockResource.cs
- DesignerSerializerAttribute.cs
- JsonReader.cs
- AtomicFile.cs
- DelegateHelpers.cs
- TextModifierScope.cs
- EncoderExceptionFallback.cs
- OutOfMemoryException.cs
- RowBinding.cs
- EnumerableRowCollection.cs
- GeneralTransform3DGroup.cs
- TableCell.cs
- Module.cs
- NavigateEvent.cs
- ValidationManager.cs