Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Xml / System / Xml / Serialization / Configuration / XmlSerializerSection.cs / 4 / 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
- TypedTableGenerator.cs
- MouseWheelEventArgs.cs
- XsltConvert.cs
- ItemCollection.cs
- MemberAccessException.cs
- BamlRecords.cs
- ConfigXmlAttribute.cs
- ElementsClipboardData.cs
- CommandField.cs
- CatalogPartChrome.cs
- PackagePart.cs
- DelegatedStream.cs
- Memoizer.cs
- ByteAnimationUsingKeyFrames.cs
- SafeBitVector32.cs
- COAUTHINFO.cs
- PropertyGridView.cs
- CommunicationException.cs
- ExtenderProvidedPropertyAttribute.cs
- BigInt.cs
- SerialReceived.cs
- AlignmentYValidation.cs
- DataControlLinkButton.cs
- RoutedEventConverter.cs
- HwndSubclass.cs
- TimersDescriptionAttribute.cs
- CommonXSendMessage.cs
- _SSPIWrapper.cs
- HandleCollector.cs
- MetadataItemEmitter.cs
- CompoundFileReference.cs
- SqlHelper.cs
- Duration.cs
- MinMaxParagraphWidth.cs
- ParameterCollection.cs
- DialogResultConverter.cs
- ServiceRouteHandler.cs
- ExpressionQuoter.cs
- SizeValueSerializer.cs
- HostedTcpTransportManager.cs
- MenuItem.cs
- LassoSelectionBehavior.cs
- Message.cs
- SetStateDesigner.cs
- ExchangeUtilities.cs
- HyperLinkStyle.cs
- GridViewHeaderRowPresenter.cs
- SmtpNegotiateAuthenticationModule.cs
- ChameleonKey.cs
- DropDownList.cs
- GridViewColumnHeaderAutomationPeer.cs
- TimeIntervalCollection.cs
- DefaultPropertiesToSend.cs
- PointKeyFrameCollection.cs
- QilInvoke.cs
- LocatorBase.cs
- _IPv4Address.cs
- NullReferenceException.cs
- TableSectionStyle.cs
- WebEvents.cs
- XmlSecureResolver.cs
- GeneralTransform3DGroup.cs
- EnlistmentTraceIdentifier.cs
- SerializationEventsCache.cs
- ColumnReorderedEventArgs.cs
- ECDiffieHellmanCngPublicKey.cs
- ListViewItem.cs
- Compiler.cs
- ObjectPersistData.cs
- ValidationPropertyAttribute.cs
- PropertyGeneratedEventArgs.cs
- BitmapEffect.cs
- SafeFileHandle.cs
- TimeManager.cs
- Timer.cs
- BasicExpandProvider.cs
- WebColorConverter.cs
- DataContractAttribute.cs
- CompareInfo.cs
- parserscommon.cs
- FunctionParameter.cs
- ManifestResourceInfo.cs
- FileChangesMonitor.cs
- SqlInternalConnectionTds.cs
- Image.cs
- ErasingStroke.cs
- SqlTriggerAttribute.cs
- Repeater.cs
- Profiler.cs
- Encoder.cs
- regiisutil.cs
- ManipulationDelta.cs
- JulianCalendar.cs
- ControlCollection.cs
- Hashtable.cs
- TypedReference.cs
- AuthenticationManager.cs
- FlowThrottle.cs
- XamlToRtfWriter.cs
- InternalControlCollection.cs