Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / Serialization / Configuration / XmlSerializerSection.cs / 1305376 / XmlSerializerSection.cs
namespace System.Xml.Serialization.Configuration { using System; using System.IO; using System.Web; using System.Configuration; using System.ComponentModel; using System.Globalization; using System.Reflection; using System.Resources; public sealed class XmlSerializerSection : ConfigurationSection { public XmlSerializerSection() { this.properties.Add(this.checkDeserializeAdvances); this.properties.Add(this.tempFilesLocation); } protected override ConfigurationPropertyCollection Properties { get { return this.properties; } } [ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, DefaultValue = false)] public bool CheckDeserializeAdvances { get { return (bool)this[this.checkDeserializeAdvances]; } set { this[this.checkDeserializeAdvances] = value; } } [ConfigurationProperty(ConfigurationStrings.TempFilesLocation, DefaultValue = null)] public string TempFilesLocation { get { return (string)this[this.tempFilesLocation]; } set { this[this.tempFilesLocation] = value; } } ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection(); // Supply a type converter, even though it's a plain type converter, to get around ConfigurationProperty's internal // Enum conversion routine. The internal one is case-sensitive, we want this to be case-insensitive. readonly ConfigurationProperty checkDeserializeAdvances = new ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, typeof(bool), false, ConfigurationPropertyOptions.None); readonly ConfigurationProperty tempFilesLocation = new ConfigurationProperty(ConfigurationStrings.TempFilesLocation, typeof(string), null, null, new RootedPathValidator(), ConfigurationPropertyOptions.None); } public class RootedPathValidator : ConfigurationValidatorBase { public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { string tempDirectory = value as string; if (string.IsNullOrEmpty(tempDirectory)) return; tempDirectory = tempDirectory.Trim(); if (string.IsNullOrEmpty(tempDirectory)) return; if (!Path.IsPathRooted(tempDirectory)) { // Make sure the path is not relative (VSWhidbey 260075) throw new ConfigurationErrorsException(); } char firstChar = tempDirectory[0]; if (firstChar == Path.DirectorySeparatorChar || firstChar == Path.AltDirectorySeparatorChar) { // Make sure the path is explicitly rooted throw new ConfigurationErrorsException(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Xml.Serialization.Configuration { using System; using System.IO; using System.Web; using System.Configuration; using System.ComponentModel; using System.Globalization; using System.Reflection; using System.Resources; public sealed class XmlSerializerSection : ConfigurationSection { public XmlSerializerSection() { this.properties.Add(this.checkDeserializeAdvances); this.properties.Add(this.tempFilesLocation); } protected override ConfigurationPropertyCollection Properties { get { return this.properties; } } [ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, DefaultValue = false)] public bool CheckDeserializeAdvances { get { return (bool)this[this.checkDeserializeAdvances]; } set { this[this.checkDeserializeAdvances] = value; } } [ConfigurationProperty(ConfigurationStrings.TempFilesLocation, DefaultValue = null)] public string TempFilesLocation { get { return (string)this[this.tempFilesLocation]; } set { this[this.tempFilesLocation] = value; } } ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection(); // Supply a type converter, even though it's a plain type converter, to get around ConfigurationProperty's internal // Enum conversion routine. The internal one is case-sensitive, we want this to be case-insensitive. readonly ConfigurationProperty checkDeserializeAdvances = new ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, typeof(bool), false, ConfigurationPropertyOptions.None); readonly ConfigurationProperty tempFilesLocation = new ConfigurationProperty(ConfigurationStrings.TempFilesLocation, typeof(string), null, null, new RootedPathValidator(), ConfigurationPropertyOptions.None); } public class RootedPathValidator : ConfigurationValidatorBase { public override bool CanValidate(Type type) { return (type == typeof(string)); } public override void Validate(object value) { string tempDirectory = value as string; if (string.IsNullOrEmpty(tempDirectory)) return; tempDirectory = tempDirectory.Trim(); if (string.IsNullOrEmpty(tempDirectory)) return; if (!Path.IsPathRooted(tempDirectory)) { // Make sure the path is not relative (VSWhidbey 260075) throw new ConfigurationErrorsException(); } char firstChar = tempDirectory[0]; if (firstChar == Path.DirectorySeparatorChar || firstChar == Path.AltDirectorySeparatorChar) { // Make sure the path is explicitly rooted throw new ConfigurationErrorsException(); } } } } // 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
- _FtpControlStream.cs
- RijndaelManagedTransform.cs
- CircleHotSpot.cs
- CodeSnippetCompileUnit.cs
- MouseOverProperty.cs
- GroupBox.cs
- QueueProcessor.cs
- GridViewRowEventArgs.cs
- ReceiveContent.cs
- FacetChecker.cs
- ValueType.cs
- DoubleLink.cs
- WebException.cs
- SmtpClient.cs
- Page.cs
- SQLDoubleStorage.cs
- CodeGen.cs
- RuleConditionDialog.cs
- CodeCastExpression.cs
- ColumnResult.cs
- ItemCheckEvent.cs
- HttpListener.cs
- AdapterUtil.cs
- EntityCollection.cs
- precedingsibling.cs
- CompositeControlDesigner.cs
- ToolStripDropDownMenu.cs
- Console.cs
- BindableAttribute.cs
- DataTable.cs
- Expander.cs
- Style.cs
- DataServiceException.cs
- VersionPair.cs
- SqlConnectionPoolProviderInfo.cs
- SplineKeyFrames.cs
- _TLSstream.cs
- WebZone.cs
- CalendarDay.cs
- XsdDateTime.cs
- VsPropertyGrid.cs
- basecomparevalidator.cs
- DuplicateDetector.cs
- DbConnectionPoolGroup.cs
- Rijndael.cs
- EntityContainerRelationshipSetEnd.cs
- DocumentOutline.cs
- ExpressionsCollectionEditor.cs
- Internal.cs
- ColorTransform.cs
- BatchStream.cs
- COM2EnumConverter.cs
- LateBoundBitmapDecoder.cs
- SqlServer2KCompatibilityCheck.cs
- PermissionListSet.cs
- SecurityUniqueId.cs
- XsdBuilder.cs
- Overlapped.cs
- XmlSchemaSequence.cs
- TraceListeners.cs
- ApplicationDirectory.cs
- _SafeNetHandles.cs
- SplashScreen.cs
- SyntaxCheck.cs
- DiscoveryClientBindingElement.cs
- NetMsmqBindingElement.cs
- Cell.cs
- FontDriver.cs
- WindowPattern.cs
- Stylesheet.cs
- PassportPrincipal.cs
- Buffer.cs
- NotifyCollectionChangedEventArgs.cs
- CompatibleIComparer.cs
- SoapFault.cs
- XmlILModule.cs
- DelegatingTypeDescriptionProvider.cs
- KeyMatchBuilder.cs
- TreeViewAutomationPeer.cs
- InputLanguageProfileNotifySink.cs
- QilExpression.cs
- XmlDocument.cs
- _NetworkingPerfCounters.cs
- PrtCap_Base.cs
- XmlNamespaceMapping.cs
- ArrangedElement.cs
- StylusPointPropertyId.cs
- DbSourceParameterCollection.cs
- Update.cs
- DataRelationCollection.cs
- ComboBox.cs
- TagMapInfo.cs
- LinqDataSourceDeleteEventArgs.cs
- Calendar.cs
- QueryReaderSettings.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- ErrorHandlerModule.cs
- TCPListener.cs
- SymDocumentType.cs
- Underline.cs