Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Net / System / Net / Configuration / TimeoutValidationAttribute.cs / 1 / TimeoutValidationAttribute.cs
namespace System.Net { using System; using System.Configuration; using System.ComponentModel; // NOTE [[....]]: The old validation attribute was removed from System.ll and is // replaced by more flexible and robust validation/conversion design. // The change bellow is a simple fix to make things work with the least possible change ( it is an integration break ) // However, we already have a built-in support for configuration properties that store // Type names. We do reccomend that all uses of the validator bellow are converted to // properties of type Type ( instead of string ) which use the TypeNameConverter from System.Configuration.dll // Feel free to ask me for more details if you decide to do the conversion internal sealed class TimeoutValidator : ConfigurationValidatorBase { bool _zeroValid = false; internal TimeoutValidator(bool zeroValid) { _zeroValid = zeroValid; } public override bool CanValidate( Type type ) { return ( type == typeof( int ) || type == typeof( long ) ); } public override void Validate( object value ) { if (value == null) return; int timeout = (int)value; if (_zeroValid && timeout == 0) return; if (timeout <= 0 && timeout != System.Threading.Timeout.Infinite) { // Note [[....]] : This is a lab integration fix. Old code did not have any error message at this point // This code change accomplishes the same result. However its highly reccomended that a specific error message is givven // to the user so they know what exaclty is the problem ( i.e. the value must be a positive integer or be Infinite ) // To accomplish this - an exception with the specific error message could be thrown ( ArgumentException is prefferred ) throw new ConfigurationErrorsException(SR.GetString(SR.net_io_timeout_use_gt_zero)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Net { using System; using System.Configuration; using System.ComponentModel; // NOTE [[....]]: The old validation attribute was removed from System.ll and is // replaced by more flexible and robust validation/conversion design. // The change bellow is a simple fix to make things work with the least possible change ( it is an integration break ) // However, we already have a built-in support for configuration properties that store // Type names. We do reccomend that all uses of the validator bellow are converted to // properties of type Type ( instead of string ) which use the TypeNameConverter from System.Configuration.dll // Feel free to ask me for more details if you decide to do the conversion internal sealed class TimeoutValidator : ConfigurationValidatorBase { bool _zeroValid = false; internal TimeoutValidator(bool zeroValid) { _zeroValid = zeroValid; } public override bool CanValidate( Type type ) { return ( type == typeof( int ) || type == typeof( long ) ); } public override void Validate( object value ) { if (value == null) return; int timeout = (int)value; if (_zeroValid && timeout == 0) return; if (timeout <= 0 && timeout != System.Threading.Timeout.Infinite) { // Note [[....]] : This is a lab integration fix. Old code did not have any error message at this point // This code change accomplishes the same result. However its highly reccomended that a specific error message is givven // to the user so they know what exaclty is the problem ( i.e. the value must be a positive integer or be Infinite ) // To accomplish this - an exception with the specific error message could be thrown ( ArgumentException is prefferred ) throw new ConfigurationErrorsException(SR.GetString(SR.net_io_timeout_use_gt_zero)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DeploymentExceptionMapper.cs
- XPathDescendantIterator.cs
- streamingZipPartStream.cs
- TagPrefixCollection.cs
- ItemList.cs
- WebPartCancelEventArgs.cs
- ControlCollection.cs
- ToolboxItemAttribute.cs
- Overlapped.cs
- CaretElement.cs
- Panel.cs
- WebBaseEventKeyComparer.cs
- Encoder.cs
- ThumbAutomationPeer.cs
- SqlFunctions.cs
- EntityDataSource.cs
- TextEditorSpelling.cs
- AutomationElementIdentifiers.cs
- ProcessHostMapPath.cs
- ArraySegment.cs
- XmlILOptimizerVisitor.cs
- SiteMapNodeItem.cs
- AddingNewEventArgs.cs
- XhtmlCssHandler.cs
- WebEventTraceProvider.cs
- CommonDialog.cs
- _UncName.cs
- RSACryptoServiceProvider.cs
- ColumnReorderedEventArgs.cs
- StrongNameUtility.cs
- InputLanguageProfileNotifySink.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DataServiceProcessingPipelineEventArgs.cs
- GacUtil.cs
- printdlgexmarshaler.cs
- ObjectToIdCache.cs
- DataGridView.cs
- HierarchicalDataSourceControl.cs
- CancellationTokenSource.cs
- WebServiceFault.cs
- JsonDeserializer.cs
- HttpResponseWrapper.cs
- DbConnectionPool.cs
- MetadataArtifactLoaderFile.cs
- AssemblyHash.cs
- DesignerSerializationOptionsAttribute.cs
- BooleanProjectedSlot.cs
- ElapsedEventArgs.cs
- ProfessionalColorTable.cs
- NoPersistHandle.cs
- ConfigurationStrings.cs
- RawMouseInputReport.cs
- MetaDataInfo.cs
- DbConnectionPoolGroup.cs
- DataBoundControl.cs
- CollectionsUtil.cs
- RoleManagerSection.cs
- Ray3DHitTestResult.cs
- ReachFixedPageSerializer.cs
- BinaryFormatter.cs
- xml.cs
- EntityCollection.cs
- StrongNameUtility.cs
- IDictionary.cs
- ObjectListSelectEventArgs.cs
- HierarchicalDataSourceControl.cs
- ZipPackagePart.cs
- ProcessThreadCollection.cs
- UnconditionalPolicy.cs
- PartitionerStatic.cs
- XmlAnyElementAttribute.cs
- SafeWaitHandle.cs
- DefaultDiscoveryService.cs
- ProcessDesigner.cs
- CultureInfoConverter.cs
- ApplicationInterop.cs
- SessionEndedEventArgs.cs
- MiniModule.cs
- TemplateField.cs
- HyperlinkAutomationPeer.cs
- CriticalHandle.cs
- ResourceLoader.cs
- SoapReflectionImporter.cs
- SamlAttributeStatement.cs
- DefaultPropertiesToSend.cs
- ProviderUtil.cs
- SolidColorBrush.cs
- Color.cs
- StateManagedCollection.cs
- ViewCellSlot.cs
- ApplicationProxyInternal.cs
- DataGridCell.cs
- ReaderContextStackData.cs
- PageFunction.cs
- ConfigXmlAttribute.cs
- Canonicalizers.cs
- FileStream.cs
- IisHelper.cs
- SystemIPv4InterfaceProperties.cs
- SQlBooleanStorage.cs