Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Xml / System / Xml / Serialization / Configuration / XmlSerializerSection.cs / 4 / 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
- SafeProcessHandle.cs
- WeakHashtable.cs
- StringUtil.cs
- MessageDescriptionCollection.cs
- FixedFindEngine.cs
- PrinterSettings.cs
- XmlSchemaAnnotated.cs
- DragStartedEventArgs.cs
- WindowInteropHelper.cs
- VerificationException.cs
- DbDataReader.cs
- TrackingProfileDeserializationException.cs
- SQLDecimalStorage.cs
- IPPacketInformation.cs
- IdentityNotMappedException.cs
- FileUpload.cs
- DataGridViewCellParsingEventArgs.cs
- ServiceChannelManager.cs
- DependencyPropertyValueSerializer.cs
- CacheMemory.cs
- SecurityKeyType.cs
- DataListItemCollection.cs
- SrgsToken.cs
- ControlCollection.cs
- GlyphRunDrawing.cs
- TextRangeAdaptor.cs
- Normalizer.cs
- ManualWorkflowSchedulerService.cs
- XsltContext.cs
- DefaultAssemblyResolver.cs
- StringFormat.cs
- Bidi.cs
- EntityDataSourceView.cs
- Wildcard.cs
- DynamicMethod.cs
- ActivityWithResult.cs
- GroupLabel.cs
- SiteMapProvider.cs
- BindingCompleteEventArgs.cs
- CompilationSection.cs
- ReferencedType.cs
- Splitter.cs
- QuaternionKeyFrameCollection.cs
- ListCollectionView.cs
- CompilerGlobalScopeAttribute.cs
- PathSegmentCollection.cs
- TabControl.cs
- ColorDialog.cs
- VisualStyleElement.cs
- WindowsListViewItem.cs
- ItemsPanelTemplate.cs
- BasicKeyConstraint.cs
- SoapAttributeOverrides.cs
- COM2PictureConverter.cs
- HandleScope.cs
- WebRequestModuleElementCollection.cs
- PropertyChange.cs
- TableItemProviderWrapper.cs
- Size3DValueSerializer.cs
- ServiceDocumentFormatter.cs
- Logging.cs
- BamlLocalizableResource.cs
- TransformerConfigurationWizardBase.cs
- XpsStructure.cs
- ListMarkerLine.cs
- StreamAsIStream.cs
- DataComponentNameHandler.cs
- backend.cs
- BitmapEncoder.cs
- ReaderOutput.cs
- QueryAsyncResult.cs
- PointAnimationBase.cs
- Rijndael.cs
- TextCharacters.cs
- MappingItemCollection.cs
- File.cs
- ChildChangedEventArgs.cs
- DBDataPermission.cs
- CodeTypeDeclarationCollection.cs
- MonitorWrapper.cs
- UnhandledExceptionEventArgs.cs
- ActiveXHost.cs
- HttpResponseHeader.cs
- PrintControllerWithStatusDialog.cs
- entityreference_tresulttype.cs
- Pair.cs
- BitmapSizeOptions.cs
- UnlockInstanceAsyncResult.cs
- AssemblyInfo.cs
- StringUtil.cs
- DynamicRendererThreadManager.cs
- OleDbParameter.cs
- AppSettingsReader.cs
- PerformanceCounterPermissionEntryCollection.cs
- ParsedAttributeCollection.cs
- _NetRes.cs
- AlgoModule.cs
- FillErrorEventArgs.cs
- DataGridViewCellMouseEventArgs.cs
- ValidationHelper.cs