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
- UnsignedPublishLicense.cs
- MethodExpr.cs
- TablePattern.cs
- HtmlListAdapter.cs
- ScriptManager.cs
- Cloud.cs
- ScriptMethodAttribute.cs
- UnsafeNativeMethodsCLR.cs
- DBCommandBuilder.cs
- TextMetrics.cs
- EastAsianLunisolarCalendar.cs
- InheritedPropertyDescriptor.cs
- TopClause.cs
- SecurityTokenSerializer.cs
- WindowsRichEditRange.cs
- DbModificationClause.cs
- MyContact.cs
- XpsFilter.cs
- CanExecuteRoutedEventArgs.cs
- HealthMonitoringSectionHelper.cs
- CompareValidator.cs
- FeatureSupport.cs
- DuplicateWaitObjectException.cs
- WeakReference.cs
- TextEditorSelection.cs
- RuntimeResourceSet.cs
- ObjectViewEntityCollectionData.cs
- BasicDesignerLoader.cs
- UnknownWrapper.cs
- RawUIStateInputReport.cs
- ValidatorCompatibilityHelper.cs
- Themes.cs
- PolyQuadraticBezierSegment.cs
- MaskInputRejectedEventArgs.cs
- CallContext.cs
- DataListItemCollection.cs
- WebRequest.cs
- KeyConverter.cs
- FindRequestContext.cs
- PixelFormatConverter.cs
- Transform3DGroup.cs
- HtmlCalendarAdapter.cs
- UrlAuthorizationModule.cs
- OrderingQueryOperator.cs
- Vector3DAnimationUsingKeyFrames.cs
- ResponseBodyWriter.cs
- BaseProcessor.cs
- MetaModel.cs
- XmlLangPropertyAttribute.cs
- Color.cs
- Int32Animation.cs
- ProfileService.cs
- XPathDocumentNavigator.cs
- WebPartZoneCollection.cs
- TypeForwardedToAttribute.cs
- ChannelServices.cs
- WebPartCloseVerb.cs
- EntityConnection.cs
- AlignmentYValidation.cs
- OpCodes.cs
- TextOnlyOutput.cs
- ChtmlCalendarAdapter.cs
- ClientFormsIdentity.cs
- StickyNoteHelper.cs
- SQLResource.cs
- ProxyWebPartManager.cs
- WebRequestModuleElementCollection.cs
- CustomErrorsSectionWrapper.cs
- JoinElimination.cs
- FileLogRecordEnumerator.cs
- XamlStyleSerializer.cs
- SQLInt32Storage.cs
- ExpressionCopier.cs
- WinInetCache.cs
- AssemblyResourceLoader.cs
- ConstructorNeedsTagAttribute.cs
- FieldToken.cs
- FixedPage.cs
- ErrorActivity.cs
- VBIdentifierName.cs
- SrgsElementFactory.cs
- DecimalStorage.cs
- PeerPresenceInfo.cs
- DeferredTextReference.cs
- FormsIdentity.cs
- SoapIgnoreAttribute.cs
- EntityClientCacheKey.cs
- BitmapSizeOptions.cs
- AddInActivator.cs
- SelectionProcessor.cs
- DefinitionUpdate.cs
- DbConnectionPoolGroupProviderInfo.cs
- WebPartAddingEventArgs.cs
- CompilerWrapper.cs
- RSACryptoServiceProvider.cs
- WindowsRebar.cs
- RuntimeConfigLKG.cs
- NamespaceCollection.cs
- CheckBox.cs
- GeneralTransform2DTo3DTo2D.cs