Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Xml / System / Xml / Serialization / Configuration / XmlSerializerSection.cs / 1 / 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
- cookiecollection.cs
- SiteMapDataSourceView.cs
- Guid.cs
- HttpListenerResponse.cs
- ScriptIgnoreAttribute.cs
- ClaimComparer.cs
- KeyedCollection.cs
- CatalogPart.cs
- dsa.cs
- ButtonBaseAutomationPeer.cs
- DownloadProgressEventArgs.cs
- DefaultClaimSet.cs
- InternalsVisibleToAttribute.cs
- ObjectDataSourceStatusEventArgs.cs
- XmlSerializationWriter.cs
- BlobPersonalizationState.cs
- MultiTrigger.cs
- TypeResolvingOptions.cs
- XmlElementAttributes.cs
- SoundPlayerAction.cs
- MDIWindowDialog.cs
- RepeaterItemEventArgs.cs
- PkcsUtils.cs
- StyleCollection.cs
- DefaultValueTypeConverter.cs
- UniqueConstraint.cs
- SynchronizationContext.cs
- Event.cs
- Documentation.cs
- EnumValidator.cs
- SoapTransportImporter.cs
- CompilationRelaxations.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- HttpDebugHandler.cs
- HttpServerVarsCollection.cs
- NumberAction.cs
- ImageList.cs
- TimeEnumHelper.cs
- SHA512Managed.cs
- SqlConnectionFactory.cs
- EventWaitHandle.cs
- Version.cs
- mactripleDES.cs
- TcpSocketManager.cs
- QuadTree.cs
- RoutedUICommand.cs
- EventSinkHelperWriter.cs
- DataTableCollection.cs
- MetadataSerializer.cs
- DbMetaDataCollectionNames.cs
- BindingMAnagerBase.cs
- IndicCharClassifier.cs
- SpellerError.cs
- MouseGesture.cs
- TextDecoration.cs
- ProfileParameter.cs
- _ListenerResponseStream.cs
- ChannelSinkStacks.cs
- FontNamesConverter.cs
- DomainLiteralReader.cs
- ObjectNotFoundException.cs
- EventDescriptorCollection.cs
- GenericIdentity.cs
- MessageSecurityTokenVersion.cs
- TreeBuilder.cs
- SelectionEditingBehavior.cs
- categoryentry.cs
- InstanceDescriptor.cs
- OdbcConnectionOpen.cs
- SinglePhaseEnlistment.cs
- MasterPageCodeDomTreeGenerator.cs
- PriorityRange.cs
- TextProviderWrapper.cs
- Image.cs
- InputProviderSite.cs
- TextCollapsingProperties.cs
- EntityRecordInfo.cs
- ScriptDescriptor.cs
- System.Data.OracleClient_BID.cs
- EnlistmentTraceIdentifier.cs
- WebPartHeaderCloseVerb.cs
- EmissiveMaterial.cs
- InputManager.cs
- RadioButton.cs
- XmlAttributeAttribute.cs
- PartialClassGenerationTask.cs
- RepeaterItem.cs
- InputLanguageProfileNotifySink.cs
- FileUpload.cs
- HideDisabledControlAdapter.cs
- WebBrowserContainer.cs
- StatusBarAutomationPeer.cs
- DbModificationCommandTree.cs
- ConstraintEnumerator.cs
- HtmlInputReset.cs
- ViewStateModeByIdAttribute.cs
- TemplateInstanceAttribute.cs
- AdornerPresentationContext.cs
- URL.cs
- StatusBarItemAutomationPeer.cs