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
- ListItemCollection.cs
- HtmlElementCollection.cs
- XsltException.cs
- MailWebEventProvider.cs
- ConnectionManagementSection.cs
- ThreadPool.cs
- SortedDictionary.cs
- SecurityTokenSerializer.cs
- StateMachine.cs
- AlgoModule.cs
- AuthorizationSection.cs
- TransformFinalBlockRequest.cs
- NetNamedPipeBindingElement.cs
- XmlSchemaResource.cs
- QuaternionRotation3D.cs
- DataStreams.cs
- MdiWindowListStrip.cs
- BasicCellRelation.cs
- Serialization.cs
- SerialStream.cs
- BlurEffect.cs
- Vector3dCollection.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- ThicknessKeyFrameCollection.cs
- ToolStripOverflowButton.cs
- SqlMetaData.cs
- DesignerActionTextItem.cs
- ErrorInfoXmlDocument.cs
- _TimerThread.cs
- ObjectItemNoOpAssemblyLoader.cs
- FunctionCommandText.cs
- SelectedPathEditor.cs
- ToolboxItem.cs
- EventMappingSettings.cs
- OutputCacheProfile.cs
- WindowsListViewItemCheckBox.cs
- PagesChangedEventArgs.cs
- EncodingInfo.cs
- WebPartEditVerb.cs
- UpDownBase.cs
- SoundPlayer.cs
- AsymmetricKeyExchangeDeformatter.cs
- ControlPropertyNameConverter.cs
- OleDbConnectionFactory.cs
- PaperSize.cs
- SchemaAttDef.cs
- TdsParser.cs
- OracleParameterCollection.cs
- ColorKeyFrameCollection.cs
- AssemblyName.cs
- XsltOutput.cs
- XmlMemberMapping.cs
- StateDesigner.LayoutSelectionGlyph.cs
- SmtpFailedRecipientException.cs
- Profiler.cs
- EventRouteFactory.cs
- TextEditorMouse.cs
- PropertyBuilder.cs
- RepeatButtonAutomationPeer.cs
- CookieParameter.cs
- ServiceProviders.cs
- ErrorWrapper.cs
- EtwTrace.cs
- PlainXmlDeserializer.cs
- SpellerStatusTable.cs
- VisualBrush.cs
- RSAPKCS1SignatureDeformatter.cs
- RemotingException.cs
- BufferedGraphicsContext.cs
- TypeSystem.cs
- DetailsViewRowCollection.cs
- BitmapPalette.cs
- InstanceNormalEvent.cs
- RuleConditionDialog.Designer.cs
- ColumnTypeConverter.cs
- WebRequestModuleElement.cs
- DataGridViewHitTestInfo.cs
- Pen.cs
- TimersDescriptionAttribute.cs
- updatecommandorderer.cs
- HtmlInputReset.cs
- ViewStateModeByIdAttribute.cs
- ToolStripSeparator.cs
- SectionInformation.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- odbcmetadatafactory.cs
- ConditionalAttribute.cs
- BulletedListEventArgs.cs
- sortedlist.cs
- AdornerHitTestResult.cs
- OleDbMetaDataFactory.cs
- PointUtil.cs
- SeverityFilter.cs
- SchemaElement.cs
- MappedMetaModel.cs
- X509CertificateRecipientClientCredential.cs
- ResourceCodeDomSerializer.cs
- BindingMAnagerBase.cs
- CancelRequestedRecord.cs
- VersionedStreamOwner.cs