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
- WebServiceFaultDesigner.cs
- MaskInputRejectedEventArgs.cs
- PageMediaType.cs
- Vector3DValueSerializer.cs
- Delegate.cs
- SecurityAppliedMessage.cs
- TemplateControl.cs
- ProxyWebPartManagerDesigner.cs
- PeerCollaborationPermission.cs
- AlignmentXValidation.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- GacUtil.cs
- TaskForm.cs
- TextElementEnumerator.cs
- Rect.cs
- SqlConnectionManager.cs
- UnsafeNativeMethodsCLR.cs
- Message.cs
- DataGridTablesFactory.cs
- ISO2022Encoding.cs
- RadioButtonPopupAdapter.cs
- XDRSchema.cs
- UriGenerator.cs
- COSERVERINFO.cs
- DashStyles.cs
- TextDecorationCollectionConverter.cs
- HybridDictionary.cs
- ForeignKeyConstraint.cs
- FileUtil.cs
- LoginNameDesigner.cs
- OleDbPermission.cs
- FormViewModeEventArgs.cs
- TableLayoutPanelResizeGlyph.cs
- IPipelineRuntime.cs
- GeneralTransform3DTo2DTo3D.cs
- AuthenticatingEventArgs.cs
- ColorContextHelper.cs
- AdPostCacheSubstitution.cs
- AssemblyBuilder.cs
- Brush.cs
- GridLengthConverter.cs
- TextOnlyOutput.cs
- TagNameToTypeMapper.cs
- TableRowCollection.cs
- RowUpdatedEventArgs.cs
- BamlResourceSerializer.cs
- XmlHierarchicalEnumerable.cs
- DesignerSerializerAttribute.cs
- OleDragDropHandler.cs
- Constraint.cs
- TextTreeUndo.cs
- Geometry.cs
- ObjectDataSource.cs
- BindableTemplateBuilder.cs
- WebPartDisplayModeCancelEventArgs.cs
- RowsCopiedEventArgs.cs
- HttpListenerElement.cs
- Assembly.cs
- DelegatingTypeDescriptionProvider.cs
- PartialTrustVisibleAssemblyCollection.cs
- Constraint.cs
- TemplateComponentConnector.cs
- RegexWriter.cs
- EncodingFallbackAwareXmlTextWriter.cs
- XmlNodeReader.cs
- SequentialWorkflowHeaderFooter.cs
- ConfigurationElement.cs
- RelationshipNavigation.cs
- DescriptionAttribute.cs
- SortDescriptionCollection.cs
- SemanticResultValue.cs
- ShadowGlyph.cs
- XPathChildIterator.cs
- ZoneIdentityPermission.cs
- DropShadowBitmapEffect.cs
- XsltLoader.cs
- CompiledIdentityConstraint.cs
- SqlLiftWhereClauses.cs
- XmlBuffer.cs
- EventLogEntryCollection.cs
- ComplexLine.cs
- DataGridColumnEventArgs.cs
- ProfileGroupSettingsCollection.cs
- ServiceDescription.cs
- HttpHandlerAction.cs
- DataMemberFieldEditor.cs
- SafeNativeMethodsOther.cs
- UniqueID.cs
- FileClassifier.cs
- SafeMemoryMappedViewHandle.cs
- RawTextInputReport.cs
- DBDataPermission.cs
- Table.cs
- EmissiveMaterial.cs
- TypeDescriptionProvider.cs
- NameValueFileSectionHandler.cs
- TreeViewEvent.cs
- SetterBase.cs
- ExtenderProvidedPropertyAttribute.cs
- KeyTimeConverter.cs