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
- AutomationPattern.cs
- ConnectionsZone.cs
- Binding.cs
- SerialReceived.cs
- SqlBuilder.cs
- SettingsPropertyWrongTypeException.cs
- ButtonChrome.cs
- FormsAuthenticationTicket.cs
- SqlConnectionPoolProviderInfo.cs
- XhtmlTextWriter.cs
- PersonalizableTypeEntry.cs
- RegexWriter.cs
- SendMailErrorEventArgs.cs
- arc.cs
- ApplicationActivator.cs
- StreamUpgradeInitiator.cs
- XmlUtilWriter.cs
- HideDisabledControlAdapter.cs
- XamlSerializationHelper.cs
- StandardOleMarshalObject.cs
- EndpointConfigContainer.cs
- WaitForChangedResult.cs
- StrongNameUtility.cs
- XPathDescendantIterator.cs
- SqlParameter.cs
- EdmRelationshipRoleAttribute.cs
- ComNativeDescriptor.cs
- ExtractorMetadata.cs
- DrawListViewItemEventArgs.cs
- DataGridViewSortCompareEventArgs.cs
- InkCanvasAutomationPeer.cs
- MonthChangedEventArgs.cs
- WebBrowser.cs
- DataGridParentRows.cs
- CacheDependency.cs
- TreeNodeEventArgs.cs
- RangeValuePatternIdentifiers.cs
- Compilation.cs
- MatchingStyle.cs
- DependencyObject.cs
- MessagePropertyDescription.cs
- UInt32.cs
- PartialCachingAttribute.cs
- CryptoProvider.cs
- TextParaLineResult.cs
- NavigationPropertySingletonExpression.cs
- NativeRecognizer.cs
- ServiceHostingEnvironment.cs
- InfoCardSchemas.cs
- ContainerParaClient.cs
- WindowsComboBox.cs
- TextTrailingCharacterEllipsis.cs
- ResourceDefaultValueAttribute.cs
- EventToken.cs
- XmlSchemaGroupRef.cs
- RegexGroupCollection.cs
- SerializableAttribute.cs
- SoapClientMessage.cs
- OleDbRowUpdatingEvent.cs
- SignedPkcs7.cs
- GeneratedContractType.cs
- DictionarySurrogate.cs
- ClientSponsor.cs
- OpenFileDialog.cs
- GacUtil.cs
- TextElementAutomationPeer.cs
- BindingUtils.cs
- Connector.xaml.cs
- PackageDigitalSignature.cs
- CodeSubDirectoriesCollection.cs
- SimpleRecyclingCache.cs
- MappingModelBuildProvider.cs
- PointKeyFrameCollection.cs
- PageRequestManager.cs
- PartitionerStatic.cs
- AnimationLayer.cs
- SqlCacheDependencyDatabase.cs
- ElementFactory.cs
- UxThemeWrapper.cs
- ToolStripRenderEventArgs.cs
- ExpressionPrefixAttribute.cs
- VoiceObjectToken.cs
- AlphabetConverter.cs
- DBDataPermission.cs
- XmlCollation.cs
- Point.cs
- HMACRIPEMD160.cs
- MenuEventArgs.cs
- XmlSchemaProviderAttribute.cs
- OdbcConnectionPoolProviderInfo.cs
- ContextStack.cs
- SafeBitVector32.cs
- SqlCommandSet.cs
- TypeNameHelper.cs
- AssemblyInfo.cs
- DataGridViewRowConverter.cs
- ObjectTypeMapping.cs
- EntityContainerEmitter.cs
- OdbcTransaction.cs
- EntitySetBase.cs