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
- SafeReversePInvokeHandle.cs
- ArrayHelper.cs
- XdrBuilder.cs
- TextAdaptor.cs
- DBDataPermissionAttribute.cs
- TabPage.cs
- CfgSemanticTag.cs
- DataListCommandEventArgs.cs
- ControlCollection.cs
- Trace.cs
- BuildDependencySet.cs
- TripleDESCryptoServiceProvider.cs
- OracleCommandBuilder.cs
- EventQueueState.cs
- GlobalizationAssembly.cs
- FixedSchema.cs
- TreeNode.cs
- WebPartAddingEventArgs.cs
- SafeFindHandle.cs
- CodeDOMProvider.cs
- FormsAuthentication.cs
- ScriptControlManager.cs
- WindowPatternIdentifiers.cs
- SmiContextFactory.cs
- RootDesignerSerializerAttribute.cs
- AuthStoreRoleProvider.cs
- StatusBarDrawItemEvent.cs
- QueryCacheKey.cs
- RolePrincipal.cs
- BindingCollection.cs
- HandledEventArgs.cs
- ACL.cs
- LogPolicy.cs
- SqlDataSourceFilteringEventArgs.cs
- DataGridToolTip.cs
- TimeoutHelper.cs
- KeyManager.cs
- MemberBinding.cs
- MgmtConfigurationRecord.cs
- RuleAction.cs
- FtpWebResponse.cs
- ConfigurationManagerInternalFactory.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- ProfilePropertyNameValidator.cs
- ThreadExceptionDialog.cs
- FontStretch.cs
- RawStylusActions.cs
- StyleModeStack.cs
- XmlWriter.cs
- LocationUpdates.cs
- DataServiceExpressionVisitor.cs
- OneOfScalarConst.cs
- _NtlmClient.cs
- ImageListImageEditor.cs
- EntityCodeGenerator.cs
- XMLSchema.cs
- LambdaCompiler.Generated.cs
- InputLanguage.cs
- AdornerPresentationContext.cs
- DataGridTextBoxColumn.cs
- StringCollection.cs
- AssemblyInfo.cs
- TableCellCollection.cs
- ExpressionHelper.cs
- NullNotAllowedCollection.cs
- MenuAutomationPeer.cs
- WindowsListViewItemStartMenu.cs
- Converter.cs
- HttpCookieCollection.cs
- WebContext.cs
- ProcessInputEventArgs.cs
- GenerateTemporaryTargetAssembly.cs
- ChangeConflicts.cs
- QueryOperationResponseOfT.cs
- ForeignKeyFactory.cs
- PingReply.cs
- DataServiceStreamProviderWrapper.cs
- Bold.cs
- BitmapCacheBrush.cs
- DrawingGroup.cs
- DiagnosticTrace.cs
- WorkflowMarkupSerializer.cs
- DragDrop.cs
- WorkerRequest.cs
- RIPEMD160.cs
- TaskFileService.cs
- UpDownBase.cs
- Container.cs
- VersionedStreamOwner.cs
- XPathDescendantIterator.cs
- PerfCounterSection.cs
- StringUtil.cs
- ExtenderProviderService.cs
- ErrorFormatter.cs
- IgnoreFlushAndCloseStream.cs
- DrawingBrush.cs
- ElementProxy.cs
- ping.cs
- CapabilitiesAssignment.cs
- XmlReflectionImporter.cs