Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- SettingsAttributes.cs
- JsonCollectionDataContract.cs
- SQLDecimal.cs
- GacUtil.cs
- CachedCompositeFamily.cs
- WebPartHeaderCloseVerb.cs
- CheckBoxAutomationPeer.cs
- WebPartTracker.cs
- CodeCastExpression.cs
- ZipFileInfo.cs
- TextDecorationLocationValidation.cs
- HttpApplicationFactory.cs
- XmlBoundElement.cs
- DbConnectionHelper.cs
- Function.cs
- _RequestCacheProtocol.cs
- CacheVirtualItemsEvent.cs
- PathParser.cs
- ByteAnimationUsingKeyFrames.cs
- PolyBezierSegment.cs
- SystemIcmpV4Statistics.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- BooleanExpr.cs
- ParameterBinding.cs
- MonikerProxyAttribute.cs
- ErrorProvider.cs
- Util.cs
- FieldReference.cs
- SqlInternalConnection.cs
- UncommonField.cs
- PreviewKeyDownEventArgs.cs
- MDIControlStrip.cs
- QueryReaderSettings.cs
- Dynamic.cs
- NTAccount.cs
- basemetadatamappingvisitor.cs
- EmptyQuery.cs
- FixedLineResult.cs
- Rect3D.cs
- ObjectView.cs
- CodeGenerationManager.cs
- NetSectionGroup.cs
- SqlParameter.cs
- PassportAuthentication.cs
- FilteredSchemaElementLookUpTable.cs
- PassportPrincipal.cs
- _AuthenticationState.cs
- UrlMapping.cs
- RestHandlerFactory.cs
- SQLDouble.cs
- NamedPipeChannelFactory.cs
- ElementMarkupObject.cs
- DesignerDataConnection.cs
- X509Certificate2Collection.cs
- PropertySourceInfo.cs
- StaticTextPointer.cs
- TransactedBatchingElement.cs
- IndependentAnimationStorage.cs
- SharedPerformanceCounter.cs
- MaskInputRejectedEventArgs.cs
- WebProxyScriptElement.cs
- Visitors.cs
- KerberosTicketHashIdentifierClause.cs
- URLMembershipCondition.cs
- ScrollEventArgs.cs
- PageSetupDialog.cs
- DBCSCodePageEncoding.cs
- SystemFonts.cs
- PrinterUnitConvert.cs
- RotateTransform.cs
- EntityDataSourceConfigureObjectContextPanel.cs
- InheritanceAttribute.cs
- Asn1IntegerConverter.cs
- _SingleItemRequestCache.cs
- TrustSection.cs
- XmlSyndicationContent.cs
- FieldNameLookup.cs
- HtmlInputReset.cs
- SvcMapFile.cs
- CodePrimitiveExpression.cs
- BaseCollection.cs
- UnsafeNativeMethods.cs
- ReflectionUtil.cs
- DataTemplate.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- BasicBrowserDialog.cs
- ServicePerformanceCounters.cs
- ClockController.cs
- Page.cs
- MexHttpBindingElement.cs
- ListChangedEventArgs.cs
- NavigationExpr.cs
- VerificationException.cs
- mactripleDES.cs
- VariableDesigner.xaml.cs
- LinkedList.cs
- MultiBindingExpression.cs
- ImplicitInputBrush.cs
- CommandLineParser.cs
- _NTAuthentication.cs