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
- Point3DCollectionValueSerializer.cs
- ValidatorAttribute.cs
- SQLInt32Storage.cs
- Util.cs
- CustomAttributeFormatException.cs
- Panel.cs
- RecipientInfo.cs
- DataConnectionHelper.cs
- SoapAttributeAttribute.cs
- MethodBuilderInstantiation.cs
- EnglishPluralizationService.cs
- RefreshPropertiesAttribute.cs
- UnionExpr.cs
- Utils.cs
- MessageAction.cs
- TcpTransportManager.cs
- SpotLight.cs
- DateTimeStorage.cs
- FileRecordSequenceHelper.cs
- DeferredSelectedIndexReference.cs
- PropertyNames.cs
- CodeAttributeArgumentCollection.cs
- BufferedGraphicsContext.cs
- UsernameTokenFactoryCredential.cs
- elementinformation.cs
- GPPOINT.cs
- SystemWebExtensionsSectionGroup.cs
- COAUTHINFO.cs
- VirtualPathProvider.cs
- CodeSnippetTypeMember.cs
- SolidColorBrush.cs
- MsmqInputSessionChannel.cs
- GridViewAutomationPeer.cs
- IsolatedStorageException.cs
- RuleSetDialog.cs
- SystemIPv4InterfaceProperties.cs
- TabControl.cs
- xmlsaver.cs
- PropertyKey.cs
- TypeFieldSchema.cs
- EnvironmentPermission.cs
- ReferencedAssembly.cs
- BaseTransportHeaders.cs
- FormsAuthenticationUser.cs
- DataServiceResponse.cs
- ObjectListShowCommandsEventArgs.cs
- MailDefinition.cs
- DateTimeStorage.cs
- LineServicesRun.cs
- _AutoWebProxyScriptHelper.cs
- JapaneseLunisolarCalendar.cs
- EntityDesignerUtils.cs
- OracleColumn.cs
- UInt32.cs
- MimeTypeMapper.cs
- WsatAdminException.cs
- RoleManagerEventArgs.cs
- CodeMemberMethod.cs
- UserControl.cs
- GeneralTransform3DGroup.cs
- DataSet.cs
- CodeBlockBuilder.cs
- SocketConnection.cs
- EnvironmentPermission.cs
- HttpRawResponse.cs
- LookupNode.cs
- CutCopyPasteHelper.cs
- OleStrCAMarshaler.cs
- Vector.cs
- ImageSourceTypeConverter.cs
- CompositeScriptReferenceEventArgs.cs
- ActivationServices.cs
- IntSecurity.cs
- ConfigurationManagerHelper.cs
- ListItemConverter.cs
- WebControlAdapter.cs
- AnnotationComponentChooser.cs
- TypeUnloadedException.cs
- DataGridViewCellConverter.cs
- DataGridViewCellParsingEventArgs.cs
- RuntimeHandles.cs
- ApplicationActivator.cs
- ProcessHostConfigUtils.cs
- SiteIdentityPermission.cs
- XmlSchemaIdentityConstraint.cs
- BitmapCodecInfo.cs
- Boolean.cs
- RootBrowserWindowAutomationPeer.cs
- DateTimeConverter.cs
- DetailsViewUpdatedEventArgs.cs
- TypeReference.cs
- CheckBox.cs
- PriorityRange.cs
- ToolStripItemEventArgs.cs
- AutomationEvent.cs
- Light.cs
- WebSysDescriptionAttribute.cs
- SamlAssertionKeyIdentifierClause.cs
- VisualSerializer.cs
- PageAdapter.cs