Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / Mobile / ConfigurationSectionHelper.cs / 1305376 / ConfigurationSectionHelper.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Mobile { using System.Xml; using System.Configuration; using System.Diagnostics; using System.Globalization; [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal class ConfigurationSectionHelper { private XmlNode _currentNode = null; internal ConfigurationSectionHelper() { } internal /*public*/ XmlNode Node { get { return _currentNode; } set { _currentNode = value; } } private XmlNode GetAndRemoveAttribute(String attributeName, bool required) { XmlNode attibuteNode = _currentNode.Attributes.RemoveNamedItem(attributeName); if (required && attibuteNode == null) { String msg = SR.GetString(SR.ConfigSect_MissingAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } return attibuteNode; } internal /*public*/ String RemoveStringAttribute(String attributeName, bool required) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { if(required && (attributeNode.Value != null && attributeNode.Value.Length == 0)) { String msg = SR.GetString(SR.ConfigSect_MissingValue, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } return attributeNode.Value; } else { return null; } } #if UNUSED_CODE internal /*public*/ bool RemoveBoolAttribute(String attributeName, bool required, bool defaultValue) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { try { return bool.Parse(attributeNode.Value); } catch { String msg = SR.GetString(SR.ConfigSect_InvalidBooleanAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } } else { return defaultValue; } } internal /*public*/ int RemoveIntAttribute(String attributeName, bool required, int defaultValue) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { try { return int.Parse(attributeNode.Value, CultureInfo.InvariantCulture); } catch { String msg = SR.GetString(SR.ConfigSect_InvalidIntegerAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } } else { return defaultValue; } } #endif internal /*public*/ void CheckForUnrecognizedAttributes() { Debug.Assert(null != _currentNode); if(_currentNode.Attributes.Count != 0) { String msg = SR.GetString(SR.ConfigSect_UnknownAttr, _currentNode.Attributes[0].Name); throw new ConfigurationErrorsException(msg, _currentNode); } } internal /*public*/ bool IsWhitespaceOrComment() { Debug.Assert(null != _currentNode); return _currentNode.NodeType == XmlNodeType.Comment || _currentNode.NodeType == XmlNodeType.Whitespace; } internal /*public*/ void RejectNonElement() { Debug.Assert(null != _currentNode); if(_currentNode.NodeType != XmlNodeType.Element) { throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSect_UnrecognizedXML), _currentNode); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Mobile { using System.Xml; using System.Configuration; using System.Diagnostics; using System.Globalization; [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal class ConfigurationSectionHelper { private XmlNode _currentNode = null; internal ConfigurationSectionHelper() { } internal /*public*/ XmlNode Node { get { return _currentNode; } set { _currentNode = value; } } private XmlNode GetAndRemoveAttribute(String attributeName, bool required) { XmlNode attibuteNode = _currentNode.Attributes.RemoveNamedItem(attributeName); if (required && attibuteNode == null) { String msg = SR.GetString(SR.ConfigSect_MissingAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } return attibuteNode; } internal /*public*/ String RemoveStringAttribute(String attributeName, bool required) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { if(required && (attributeNode.Value != null && attributeNode.Value.Length == 0)) { String msg = SR.GetString(SR.ConfigSect_MissingValue, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } return attributeNode.Value; } else { return null; } } #if UNUSED_CODE internal /*public*/ bool RemoveBoolAttribute(String attributeName, bool required, bool defaultValue) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { try { return bool.Parse(attributeNode.Value); } catch { String msg = SR.GetString(SR.ConfigSect_InvalidBooleanAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } } else { return defaultValue; } } internal /*public*/ int RemoveIntAttribute(String attributeName, bool required, int defaultValue) { Debug.Assert(null != _currentNode); XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required); if(attributeNode != null) { try { return int.Parse(attributeNode.Value, CultureInfo.InvariantCulture); } catch { String msg = SR.GetString(SR.ConfigSect_InvalidIntegerAttr, attributeName); throw new ConfigurationErrorsException(msg, _currentNode); } } else { return defaultValue; } } #endif internal /*public*/ void CheckForUnrecognizedAttributes() { Debug.Assert(null != _currentNode); if(_currentNode.Attributes.Count != 0) { String msg = SR.GetString(SR.ConfigSect_UnknownAttr, _currentNode.Attributes[0].Name); throw new ConfigurationErrorsException(msg, _currentNode); } } internal /*public*/ bool IsWhitespaceOrComment() { Debug.Assert(null != _currentNode); return _currentNode.NodeType == XmlNodeType.Comment || _currentNode.NodeType == XmlNodeType.Whitespace; } internal /*public*/ void RejectNonElement() { Debug.Assert(null != _currentNode); if(_currentNode.NodeType != XmlNodeType.Element) { throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSect_UnrecognizedXML), _currentNode); } } } } // 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
- AnimatedTypeHelpers.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- MenuItemBindingCollection.cs
- SystemIPAddressInformation.cs
- ExternalDataExchangeClient.cs
- HtmlInputSubmit.cs
- WebServiceErrorEvent.cs
- WorkflowPageSetupDialog.cs
- DoubleCollection.cs
- InitialServerConnectionReader.cs
- TraceUtility.cs
- GiveFeedbackEvent.cs
- GridLength.cs
- UnsafeNativeMethods.cs
- _NetworkingPerfCounters.cs
- DataGridItem.cs
- SizeChangedInfo.cs
- Listbox.cs
- querybuilder.cs
- HostSecurityManager.cs
- DbConnectionPoolCounters.cs
- WebEventTraceProvider.cs
- _Events.cs
- GridViewCommandEventArgs.cs
- PropertyDescriptor.cs
- ParameterReplacerVisitor.cs
- ProfileGroupSettingsCollection.cs
- SharedPersonalizationStateInfo.cs
- TemplateBindingExpressionConverter.cs
- EntityContainerEmitter.cs
- DesignTimeVisibleAttribute.cs
- UpdateTracker.cs
- TrustManager.cs
- DbReferenceCollection.cs
- HttpDebugHandler.cs
- ToolStripLocationCancelEventArgs.cs
- PointAnimationBase.cs
- BitmapEffectGroup.cs
- TemplateInstanceAttribute.cs
- DataServiceConfiguration.cs
- BaseComponentEditor.cs
- Ipv6Element.cs
- ButtonFlatAdapter.cs
- ControlBuilderAttribute.cs
- AuthStoreRoleProvider.cs
- CodeCompileUnit.cs
- IxmlLineInfo.cs
- JournalEntryListConverter.cs
- ProfileModule.cs
- DecimalAnimation.cs
- MonthChangedEventArgs.cs
- InvokePattern.cs
- FillRuleValidation.cs
- CreateRefExpr.cs
- BuildManagerHost.cs
- GridViewSelectEventArgs.cs
- InvalidTimeZoneException.cs
- ComPlusDiagnosticTraceSchemas.cs
- CursorConverter.cs
- DataContext.cs
- DateTimeFormatInfoScanner.cs
- ListViewDataItem.cs
- DocumentViewerAutomationPeer.cs
- SmtpNegotiateAuthenticationModule.cs
- ToolStripScrollButton.cs
- CapabilitiesState.cs
- BindingCompleteEventArgs.cs
- WithParamAction.cs
- X509CertificateCollection.cs
- DependencyObjectProvider.cs
- VirtualizingPanel.cs
- ProfileSettingsCollection.cs
- DesignerLinkAdapter.cs
- SafeNativeMethodsCLR.cs
- ChildTable.cs
- ChannelBinding.cs
- DispatcherBuilder.cs
- DBCommandBuilder.cs
- AdornerLayer.cs
- PageContentAsyncResult.cs
- WhitespaceReader.cs
- CryptoApi.cs
- CompositeTypefaceMetrics.cs
- BitmapCodecInfo.cs
- SoundPlayerAction.cs
- AssociationProvider.cs
- BrushConverter.cs
- DesignerTransaction.cs
- ConditionalExpression.cs
- UIElement3D.cs
- SerializationObjectManager.cs
- DataServices.cs
- FlowDocumentView.cs
- x509utils.cs
- PageDeviceFont.cs
- XmlWrappingWriter.cs
- DefaultParameterValueAttribute.cs
- XmlWellformedWriterHelpers.cs
- WebPartVerbsEventArgs.cs
- Timer.cs