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
- DbException.cs
- MenuRenderer.cs
- BitmapEffectDrawing.cs
- MetadataException.cs
- AdapterUtil.cs
- InvalidComObjectException.cs
- TiffBitmapDecoder.cs
- ComContractElement.cs
- FormsAuthentication.cs
- HyperlinkAutomationPeer.cs
- Italic.cs
- DoubleCollectionValueSerializer.cs
- ConnectionPointGlyph.cs
- MsmqAppDomainProtocolHandler.cs
- versioninfo.cs
- DynamicResourceExtension.cs
- Span.cs
- StreamWriter.cs
- SQLDateTimeStorage.cs
- PlatformCulture.cs
- WebGetAttribute.cs
- ColorTransform.cs
- PermissionRequestEvidence.cs
- SelectionPattern.cs
- EventSinkHelperWriter.cs
- ThreadPool.cs
- TreeNodeCollection.cs
- CollectionContainer.cs
- HttpCookiesSection.cs
- MonikerProxyAttribute.cs
- SelectionProcessor.cs
- DebugView.cs
- SQLChars.cs
- CacheHelper.cs
- TemplateContent.cs
- Contracts.cs
- DataGridViewTextBoxEditingControl.cs
- MasterPage.cs
- DesignerDataColumn.cs
- SQLMoney.cs
- LambdaCompiler.Unary.cs
- CompModSwitches.cs
- WebPartConnectVerb.cs
- SapiInterop.cs
- CatalogPartChrome.cs
- FacetEnabledSchemaElement.cs
- EdmValidator.cs
- ControlTemplate.cs
- SchemaNotation.cs
- BitmapInitialize.cs
- EmptyEnumerator.cs
- TextTreeTextNode.cs
- LinqDataSourceSelectEventArgs.cs
- VoiceInfo.cs
- TypeDescriptionProvider.cs
- QueryAccessibilityHelpEvent.cs
- CodeConditionStatement.cs
- WebBrowserContainer.cs
- DataControlFieldCell.cs
- TokenizerHelper.cs
- DesignerCategoryAttribute.cs
- Main.cs
- SendMailErrorEventArgs.cs
- DataGridViewMethods.cs
- QueryOutputWriterV1.cs
- FileDialogCustomPlaces.cs
- OdbcDataReader.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DynamicPropertyHolder.cs
- BoundColumn.cs
- CharStorage.cs
- UnsafeNativeMethodsCLR.cs
- OlePropertyStructs.cs
- validation.cs
- WaitForChangedResult.cs
- UnsafeNetInfoNativeMethods.cs
- DataBoundControl.cs
- TokenBasedSet.cs
- OrderingExpression.cs
- ManagementDateTime.cs
- DocumentXPathNavigator.cs
- FileSystemInfo.cs
- Light.cs
- ListBoxChrome.cs
- TypedRowGenerator.cs
- ISAPIRuntime.cs
- InfoCardRSACryptoProvider.cs
- WindowsListViewItem.cs
- ObjectViewFactory.cs
- PermissionSetTriple.cs
- SqlRetyper.cs
- FormViewRow.cs
- DocumentsTrace.cs
- Point4D.cs
- loginstatus.cs
- DecimalConverter.cs
- DesignerOptionService.cs
- TextEndOfParagraph.cs
- TemplatePartAttribute.cs
- CqlGenerator.cs