Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / Util / ProviderUtil.cs / 1 / ProviderUtil.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Sec * * Copyright (c) 1998-1999, Microsoft Corporation * */ namespace System.Web.Util { using System.Collections.Specialized; using System.Web.Mail; using System.Configuration; using System.Globalization; internal static class ProviderUtil { internal const int Infinite = Int32.MaxValue; internal static void GetAndRemoveStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { val = config.Get(attrib); config.Remove(attrib); } internal static void GetAndRemovePositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } val = t; } internal static void GetAndRemovePositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetNonZeroPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } else { throw; } } if (t <= 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { GetBooleanAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { string s = config.Get(attrib); if (s == null) { return; } if (s == "true") { val = true; } else if (s == "false") { val = false; } else { throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_provider_attribute, attrib, providerName, s)); } } internal static void GetAndRemoveRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetRequiredNonEmptyStringAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetNonEmptyStringAttributeInternal(config, attrib, providerName, ref val, true); } #if UNUSED_CODE internal static void GetAndRemoveNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetNonEmptyStringAttributeInternal(config, attrib, providerName, ref val, false); config.Remove(attrib); } #endif private static void GetNonEmptyStringAttributeInternal(NameValueCollection config, string attrib, string providerName, ref string val, bool required) { string s = config.Get(attrib); // If it's (null and required) -OR- (empty string) we throw if ((s == null && required) || (s.Length == 0)) { throw new ConfigurationErrorsException( SR.GetString(SR.Provider_missing_attribute, attrib, providerName)); } val = s; } internal static void CheckUnrecognizedAttributes(NameValueCollection config, string providerName) { if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) throw new ConfigurationErrorsException( SR.GetString(SR.Unexpected_provider_attribute, attribUnrecognized, providerName)); } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BaseAutoFormat.cs
- StorageFunctionMapping.cs
- BufferAllocator.cs
- XmlSchemaParticle.cs
- WorkflowDesignerColors.cs
- FileStream.cs
- ProxyOperationRuntime.cs
- FacetChecker.cs
- DbConnectionPoolIdentity.cs
- RealizedColumnsBlock.cs
- RewritingPass.cs
- CommandField.cs
- WebEncodingValidator.cs
- PointAnimationUsingPath.cs
- DPCustomTypeDescriptor.cs
- TdsParameterSetter.cs
- MarginCollapsingState.cs
- SmtpNegotiateAuthenticationModule.cs
- DnsPermission.cs
- RangeBase.cs
- ResizeGrip.cs
- MenuAdapter.cs
- PartBasedPackageProperties.cs
- CrossContextChannel.cs
- TraceEventCache.cs
- HwndProxyElementProvider.cs
- PhoneCallDesigner.cs
- BitVector32.cs
- ScriptManagerProxy.cs
- DataContractSet.cs
- DBSqlParserColumnCollection.cs
- ILGenerator.cs
- Timer.cs
- BitVector32.cs
- SchemaInfo.cs
- TriState.cs
- DesigntimeLicenseContext.cs
- AttachInfo.cs
- BamlBinaryReader.cs
- ClientCultureInfo.cs
- RequestChannelBinder.cs
- BindingMemberInfo.cs
- XmlArrayAttribute.cs
- CheckBoxFlatAdapter.cs
- SchemaEntity.cs
- ImageListStreamer.cs
- ZoneLinkButton.cs
- Section.cs
- SymbolMethod.cs
- CellRelation.cs
- BinaryObjectInfo.cs
- Converter.cs
- DecoratedNameAttribute.cs
- Int16Animation.cs
- JapaneseCalendar.cs
- UnionQueryOperator.cs
- TypeResolver.cs
- TraceEventCache.cs
- PaginationProgressEventArgs.cs
- SafeArrayRankMismatchException.cs
- GetPageNumberCompletedEventArgs.cs
- GenerateScriptTypeAttribute.cs
- CopyOnWriteList.cs
- NativeMethods.cs
- BindValidationContext.cs
- Range.cs
- SQLInt16.cs
- SrgsSemanticInterpretationTag.cs
- XpsFilter.cs
- SqlDuplicator.cs
- IncrementalCompileAnalyzer.cs
- CodeNamespaceImportCollection.cs
- WebControlParameterProxy.cs
- Psha1DerivedKeyGenerator.cs
- HuffCodec.cs
- TextTreeUndoUnit.cs
- SiteMapDataSource.cs
- BamlMapTable.cs
- DbConnectionPool.cs
- SessionStateItemCollection.cs
- HiddenFieldPageStatePersister.cs
- OrderByLifter.cs
- TreeNodeCollection.cs
- CellTreeNode.cs
- VBCodeProvider.cs
- VariableQuery.cs
- ParallelTimeline.cs
- HtmlTernaryTree.cs
- XmlWriterSettings.cs
- BmpBitmapDecoder.cs
- ObjectDataSourceSelectingEventArgs.cs
- nulltextcontainer.cs
- NotImplementedException.cs
- GridViewItemAutomationPeer.cs
- WindowsGraphics2.cs
- ByteConverter.cs
- TextEditorParagraphs.cs
- InternalDispatchObject.cs
- SimpleHandlerBuildProvider.cs
- ExpressionBuilder.cs