Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- DataKey.cs
- TrackingMemoryStreamFactory.cs
- EnumConverter.cs
- XmlAnyElementAttribute.cs
- TimeSpanStorage.cs
- DtrList.cs
- RequiredAttributeAttribute.cs
- FileLevelControlBuilderAttribute.cs
- HttpCapabilitiesBase.cs
- PartialTrustHelpers.cs
- CriticalFileToken.cs
- DetailsViewDeletedEventArgs.cs
- SystemColors.cs
- PaintValueEventArgs.cs
- ReflectTypeDescriptionProvider.cs
- WindowsScrollBarBits.cs
- EdmItemCollection.cs
- ComplexTypeEmitter.cs
- FixedSOMPage.cs
- DelegateOutArgument.cs
- XslTransform.cs
- CodeCastExpression.cs
- Int32RectConverter.cs
- TargetInvocationException.cs
- SectionRecord.cs
- TableAdapterManagerNameHandler.cs
- Span.cs
- Binding.cs
- KeyBinding.cs
- TickBar.cs
- ConfigsHelper.cs
- GatewayIPAddressInformationCollection.cs
- ObjectDataSourceSelectingEventArgs.cs
- SelectedGridItemChangedEvent.cs
- XPathSelectionIterator.cs
- Highlights.cs
- IndexedGlyphRun.cs
- CodeActivityMetadata.cs
- SoapFault.cs
- MessageProtectionOrder.cs
- PropertyValueChangedEvent.cs
- SecurityHeader.cs
- ValidateNames.cs
- Subtree.cs
- TriggerAction.cs
- CodeCastExpression.cs
- CopyNodeSetAction.cs
- HtmlMeta.cs
- HyperLinkStyle.cs
- WebUtility.cs
- DbXmlEnabledProviderManifest.cs
- RtfNavigator.cs
- OracleInfoMessageEventArgs.cs
- CodeCatchClauseCollection.cs
- ResourceSetExpression.cs
- dsa.cs
- COM2PropertyDescriptor.cs
- ListViewDataItem.cs
- DefaultPrintController.cs
- CompressedStack.cs
- Triplet.cs
- GenerateTemporaryTargetAssembly.cs
- ValidationError.cs
- DefaultTextStoreTextComposition.cs
- DeferredElementTreeState.cs
- DBPropSet.cs
- WebPartConnectionsCancelEventArgs.cs
- UIElementAutomationPeer.cs
- Operator.cs
- CardSpaceException.cs
- Matrix3D.cs
- BindingMemberInfo.cs
- ZipIORawDataFileBlock.cs
- KeyConverter.cs
- ScaleTransform3D.cs
- TableFieldsEditor.cs
- PresentationTraceSources.cs
- WindowsNonControl.cs
- XamlGridLengthSerializer.cs
- Vector3DCollection.cs
- ToolStripItemImageRenderEventArgs.cs
- AttributeUsageAttribute.cs
- ListViewItem.cs
- ExtractCollection.cs
- DataGridTablesFactory.cs
- PropertyNames.cs
- BCryptSafeHandles.cs
- RegexReplacement.cs
- HelloMessage11.cs
- ObjectDataSourceSelectingEventArgs.cs
- PeerObject.cs
- StandardToolWindows.cs
- XmlSchemaInferenceException.cs
- TimeoutTimer.cs
- State.cs
- PipeStream.cs
- Constants.cs
- ClientConfigPaths.cs
- ProcessHostConfigUtils.cs
- FlowLayoutSettings.cs