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
- ScriptServiceAttribute.cs
- TimeSpanValidatorAttribute.cs
- DurableDispatcherAddressingFault.cs
- Size3D.cs
- TextAnchor.cs
- ResizingMessageFilter.cs
- AVElementHelper.cs
- TextMarkerSource.cs
- DispatcherEventArgs.cs
- ItemsChangedEventArgs.cs
- Attributes.cs
- SyndicationFeed.cs
- XmlNamespaceMappingCollection.cs
- ToolStripSplitButton.cs
- ButtonBaseAutomationPeer.cs
- OracleDataReader.cs
- LabelAutomationPeer.cs
- PixelShader.cs
- UriScheme.cs
- SendKeys.cs
- AsmxEndpointPickerExtension.cs
- ExpressionBuilderCollection.cs
- ProfessionalColors.cs
- Tokenizer.cs
- BitmapEffectvisualstate.cs
- ReaderWriterLock.cs
- BuildProviderCollection.cs
- EntityDataSourceContainerNameConverter.cs
- IgnoreSectionHandler.cs
- VirtualDirectoryMappingCollection.cs
- PersonalizationProviderCollection.cs
- OutputCacheProviderCollection.cs
- TextSelectionHighlightLayer.cs
- XmlQueryContext.cs
- IteratorDescriptor.cs
- hwndwrapper.cs
- PersonalizationStateQuery.cs
- ControlValuePropertyAttribute.cs
- IdentityModelDictionary.cs
- DataGridViewImageCell.cs
- TypeGenericEnumerableViewSchema.cs
- DataBindingCollection.cs
- MatrixStack.cs
- PageRouteHandler.cs
- WindowsGraphicsWrapper.cs
- IItemContainerGenerator.cs
- CookieParameter.cs
- SequenceRangeCollection.cs
- _RequestCacheProtocol.cs
- GPRECTF.cs
- MouseEventArgs.cs
- SqlAggregateChecker.cs
- LiteralControl.cs
- ConditionalAttribute.cs
- BufferedReadStream.cs
- ReachPageContentSerializer.cs
- Fonts.cs
- safelinkcollection.cs
- NativeMethods.cs
- FlowPanelDesigner.cs
- ValidatingReaderNodeData.cs
- TableLayoutColumnStyleCollection.cs
- PassportAuthentication.cs
- PersistenceTypeAttribute.cs
- FixedHyperLink.cs
- SelectiveScrollingGrid.cs
- PagePropertiesChangingEventArgs.cs
- ByteAnimationBase.cs
- IISMapPath.cs
- EventlogProvider.cs
- SystemIPGlobalProperties.cs
- GridViewColumnCollection.cs
- WindowsFormsHostPropertyMap.cs
- RuntimeWrappedException.cs
- OracleDataAdapter.cs
- Helpers.cs
- KoreanLunisolarCalendar.cs
- HtmlInputRadioButton.cs
- NestPullup.cs
- Knowncolors.cs
- ResourceReferenceExpression.cs
- DataGridViewUtilities.cs
- Vector3DAnimationUsingKeyFrames.cs
- CachedBitmap.cs
- BindUriHelper.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- IResourceProvider.cs
- ValidationErrorEventArgs.cs
- TextBox.cs
- TextView.cs
- SQLInt64.cs
- RenamedEventArgs.cs
- CacheDependency.cs
- CommonProperties.cs
- XMLDiffLoader.cs
- ISAPIRuntime.cs
- ConditionalExpression.cs
- PropertyCondition.cs
- ArcSegment.cs
- SafeCloseHandleCritical.cs