Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Configuration / System / Configuration / StringValidator.cs / 1 / StringValidator.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 StringValidator : ConfigurationValidatorBase { private int _minLength; private int _maxLength; private string _invalidChars; public StringValidator(int minLength) : this(minLength, int.MaxValue, null) { } public StringValidator(int minLength, int maxLength) : this(minLength, maxLength, null) { } public StringValidator(int minLength, int maxLength, string invalidCharacters) { _minLength = minLength; _maxLength = maxLength; _invalidChars = invalidCharacters; } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); string data = value as string; int len = (data == null ? 0 : data.Length); if (len < _minLength) { throw new ArgumentException(SR.GetString(SR.Validator_string_min_length, _minLength)); } if (len > _maxLength) { throw new ArgumentException(SR.GetString(SR.Validator_string_max_length, _maxLength)); } // Check if the string contains any invalid characters if ((len > 0) && (_invalidChars != null) && (_invalidChars.Length > 0)) { char[] array = new char[_invalidChars.Length]; _invalidChars.CopyTo(0, array, 0, _invalidChars.Length); if (data.IndexOfAny(array) != -1) { throw new ArgumentException(SR.GetString(SR.Validator_string_invalid_chars, _invalidChars)); } } } } } // 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 StringValidator : ConfigurationValidatorBase { private int _minLength; private int _maxLength; private string _invalidChars; public StringValidator(int minLength) : this(minLength, int.MaxValue, null) { } public StringValidator(int minLength, int maxLength) : this(minLength, maxLength, null) { } public StringValidator(int minLength, int maxLength, string invalidCharacters) { _minLength = minLength; _maxLength = maxLength; _invalidChars = invalidCharacters; } public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); string data = value as string; int len = (data == null ? 0 : data.Length); if (len < _minLength) { throw new ArgumentException(SR.GetString(SR.Validator_string_min_length, _minLength)); } if (len > _maxLength) { throw new ArgumentException(SR.GetString(SR.Validator_string_max_length, _maxLength)); } // Check if the string contains any invalid characters if ((len > 0) && (_invalidChars != null) && (_invalidChars.Length > 0)) { char[] array = new char[_invalidChars.Length]; _invalidChars.CopyTo(0, array, 0, _invalidChars.Length); if (data.IndexOfAny(array) != -1) { throw new ArgumentException(SR.GetString(SR.Validator_string_invalid_chars, _invalidChars)); } } } } } // 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
- IndependentAnimationStorage.cs
- FieldBuilder.cs
- ScopeElementCollection.cs
- RegexMatch.cs
- OutputBuffer.cs
- PseudoWebRequest.cs
- BaseTemplateCodeDomTreeGenerator.cs
- HandleExceptionArgs.cs
- ServerIdentity.cs
- ReadOnlyObservableCollection.cs
- DataControlFieldHeaderCell.cs
- TextEditorContextMenu.cs
- LockedActivityGlyph.cs
- ResourcesBuildProvider.cs
- FileDialog.cs
- AddInAdapter.cs
- HandlerFactoryWrapper.cs
- PropertyDescriptorComparer.cs
- recordstate.cs
- CapabilitiesUse.cs
- MaterializeFromAtom.cs
- UserControlCodeDomTreeGenerator.cs
- ResourceProviderFactory.cs
- InternalsVisibleToAttribute.cs
- AssemblyCacheEntry.cs
- SmiRecordBuffer.cs
- UseManagedPresentationBindingElement.cs
- Panel.cs
- IntegerValidator.cs
- smtpconnection.cs
- OutputCacheSettings.cs
- StrokeCollectionDefaultValueFactory.cs
- OuterProxyWrapper.cs
- DependencyPropertyKind.cs
- InvalidDataException.cs
- MatrixCamera.cs
- EntityType.cs
- BitHelper.cs
- CounterCreationDataCollection.cs
- StringAttributeCollection.cs
- EdmItemError.cs
- FlowDecision.cs
- DataPagerCommandEventArgs.cs
- ObjectListGeneralPage.cs
- Substitution.cs
- AttachedPropertyInfo.cs
- VectorAnimation.cs
- ProviderCollection.cs
- CustomAttributeFormatException.cs
- DependencyPropertyConverter.cs
- SchemaDeclBase.cs
- CompiledELinqQueryState.cs
- JsonByteArrayDataContract.cs
- UIElementHelper.cs
- BitmapMetadata.cs
- XamlWriter.cs
- UrlMappingsSection.cs
- DataControlCommands.cs
- NotificationContext.cs
- GuidTagList.cs
- LinqMaximalSubtreeNominator.cs
- HttpResponseInternalBase.cs
- TimeSpanConverter.cs
- TakeQueryOptionExpression.cs
- DelegatingChannelListener.cs
- parserscommon.cs
- CachedBitmap.cs
- CatalogPart.cs
- Metadata.cs
- SqlComparer.cs
- DataGridLinkButton.cs
- EditingCoordinator.cs
- ColorContextHelper.cs
- SelectionWordBreaker.cs
- WorkflowDesignerMessageFilter.cs
- DataGridBoolColumn.cs
- _ProxyRegBlob.cs
- ExternalFile.cs
- BindingCompleteEventArgs.cs
- MemberPathMap.cs
- BinaryMessageFormatter.cs
- TreeView.cs
- XmlCharCheckingWriter.cs
- DesignSurfaceEvent.cs
- DataGridRelationshipRow.cs
- Rotation3DKeyFrameCollection.cs
- ProxyWebPartManager.cs
- ContentElementCollection.cs
- TextEvent.cs
- XmlSchemaInferenceException.cs
- MetadataFile.cs
- RSAOAEPKeyExchangeFormatter.cs
- WinEventWrap.cs
- StaticExtensionConverter.cs
- XmlNavigatorStack.cs
- MetadataUtilsSmi.cs
- StructuredProperty.cs
- ImpersonateTokenRef.cs
- TargetPerspective.cs
- NumericUpDown.cs