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
- Funcletizer.cs
- StructuredTypeEmitter.cs
- ProfileProvider.cs
- UIInitializationException.cs
- XamlStyleSerializer.cs
- WebPartCollection.cs
- FileCodeGroup.cs
- CriticalFinalizerObject.cs
- LoginCancelEventArgs.cs
- VisualProxy.cs
- Walker.cs
- XmlDictionaryReaderQuotasElement.cs
- Rules.cs
- TrackBarRenderer.cs
- ReferenceEqualityComparer.cs
- SmtpNetworkElement.cs
- Vector3DCollectionConverter.cs
- UriTemplateDispatchFormatter.cs
- CodeTypeReferenceSerializer.cs
- WebPartMovingEventArgs.cs
- ContextMenu.cs
- Tokenizer.cs
- DocumentOrderComparer.cs
- Variable.cs
- ExtendedProperty.cs
- BamlTreeMap.cs
- TypeBuilderInstantiation.cs
- EtwTrackingBehaviorElement.cs
- SerializableTypeCodeDomSerializer.cs
- PageEventArgs.cs
- StdValidatorsAndConverters.cs
- HtmlTable.cs
- SafeEventHandle.cs
- MultiSelectRootGridEntry.cs
- TextSimpleMarkerProperties.cs
- TemplateBuilder.cs
- TextStore.cs
- DropShadowEffect.cs
- SQLResource.cs
- WebServiceAttribute.cs
- CssStyleCollection.cs
- ListItemParagraph.cs
- HttpProfileGroupBase.cs
- EditorZoneBase.cs
- Utils.cs
- SizeF.cs
- TextEditorLists.cs
- Simplifier.cs
- util.cs
- ProxyHwnd.cs
- SynchronizationHandlesCodeDomSerializer.cs
- SyndicationItemFormatter.cs
- ResourceSet.cs
- ParameterModifier.cs
- UnsafeNativeMethods.cs
- ConfigXmlCDataSection.cs
- MimeParameters.cs
- PointLightBase.cs
- BaseCodeDomTreeGenerator.cs
- OdbcRowUpdatingEvent.cs
- SiteMapNode.cs
- TemplateBamlRecordReader.cs
- HttpEncoderUtility.cs
- ToolStripRenderEventArgs.cs
- Hyperlink.cs
- RequestStatusBarUpdateEventArgs.cs
- wmiprovider.cs
- WebPartMenuStyle.cs
- SwitchLevelAttribute.cs
- ImageDrawing.cs
- AssemblyBuilder.cs
- TextViewBase.cs
- _HelperAsyncResults.cs
- WindowsStatic.cs
- TranslateTransform.cs
- BaseParaClient.cs
- InputMethodStateTypeInfo.cs
- TextMarkerSource.cs
- NameTable.cs
- ItemList.cs
- ServiceDescriptionReflector.cs
- ModuleBuilderData.cs
- SoapFault.cs
- ListenerConnectionModeReader.cs
- EmissiveMaterial.cs
- CompilerCollection.cs
- XmlSchemaSimpleType.cs
- RootBuilder.cs
- ObjectCacheHost.cs
- ComplexLine.cs
- Publisher.cs
- DataGrid.cs
- WsatTransactionFormatter.cs
- CodeTypeReferenceExpression.cs
- COM2ICategorizePropertiesHandler.cs
- Matrix.cs
- MessageContractMemberAttribute.cs
- DropTarget.cs
- CodeDomSerializer.cs
- TypeSystemProvider.cs