Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Configuration / TimeoutValidationAttribute.cs / 1305376 / 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
- HostExecutionContextManager.cs
- SimpleTableProvider.cs
- SQLRoleProvider.cs
- XmlSchemaDocumentation.cs
- ZoneMembershipCondition.cs
- DesignerHelpers.cs
- PipeSecurity.cs
- MemberPath.cs
- Content.cs
- MissingFieldException.cs
- PropertyInformationCollection.cs
- DataGridTableCollection.cs
- CannotUnloadAppDomainException.cs
- ConfigXmlText.cs
- OutputCacheSection.cs
- ContentValidator.cs
- ExtentKey.cs
- BinaryFormatterWriter.cs
- MemoryMappedView.cs
- DiscardableAttribute.cs
- PathSegment.cs
- NativeMethodsCLR.cs
- XsdDuration.cs
- SettingsBindableAttribute.cs
- ValidationManager.cs
- WorkflowServiceNamespace.cs
- DefaultWorkflowTransactionService.cs
- XslCompiledTransform.cs
- XPathSelfQuery.cs
- IntersectQueryOperator.cs
- DesignerActionPropertyItem.cs
- ExtensionQuery.cs
- SqlAliasesReferenced.cs
- Button.cs
- HotSpot.cs
- DataReaderContainer.cs
- SqlCommandSet.cs
- Parameter.cs
- AvTrace.cs
- ExpressionVisitorHelpers.cs
- _ScatterGatherBuffers.cs
- UserPreferenceChangingEventArgs.cs
- PropertyItem.cs
- MatrixAnimationUsingKeyFrames.cs
- TransactionManager.cs
- SqlFactory.cs
- ProcessHost.cs
- CultureMapper.cs
- SerializerProvider.cs
- RoutedEventArgs.cs
- CreateDataSourceDialog.cs
- Models.cs
- Mappings.cs
- StylusTip.cs
- StickyNoteHelper.cs
- DataObjectSettingDataEventArgs.cs
- CriticalExceptions.cs
- DrawingAttributesDefaultValueFactory.cs
- listitem.cs
- PolyBezierSegment.cs
- loginstatus.cs
- ExcCanonicalXml.cs
- ArithmeticException.cs
- RangeValuePatternIdentifiers.cs
- RadioButtonList.cs
- BindingContext.cs
- ExecutionProperties.cs
- FormsAuthenticationModule.cs
- ListBindingConverter.cs
- RectAnimationBase.cs
- PolicyImporterElementCollection.cs
- __FastResourceComparer.cs
- DropDownHolder.cs
- InteropAutomationProvider.cs
- ViewPort3D.cs
- ThreadExceptionEvent.cs
- TypeBrowserDialog.cs
- Configuration.cs
- ProtectedConfiguration.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Helpers.cs
- StructuredTypeEmitter.cs
- AnnouncementEventArgs.cs
- ZoomPercentageConverter.cs
- TextFormatter.cs
- LocalizationParserHooks.cs
- TextTreeRootNode.cs
- LZCodec.cs
- ContextInformation.cs
- TypeInfo.cs
- ProfileInfo.cs
- ListControlBuilder.cs
- SafeHandles.cs
- ForceCopyBuildProvider.cs
- StringUtil.cs
- SmiMetaDataProperty.cs
- CustomCategoryAttribute.cs
- ClientWindowsAuthenticationMembershipProvider.cs
- FormViewPageEventArgs.cs
- Enum.cs