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
- AuthenticationSection.cs
- ProcessHostConfigUtils.cs
- documentsequencetextview.cs
- RuleInfoComparer.cs
- MethodBuilder.cs
- SupportsEventValidationAttribute.cs
- RemotingConfiguration.cs
- TreeWalker.cs
- StreamGeometryContext.cs
- ManagementException.cs
- SR.cs
- TemplateApplicationHelper.cs
- PolyLineSegmentFigureLogic.cs
- ManagementInstaller.cs
- RIPEMD160.cs
- dsa.cs
- EnterpriseServicesHelper.cs
- ServiceModelConfigurationElementCollection.cs
- DesignTable.cs
- _ProxyChain.cs
- Context.cs
- ScriptComponentDescriptor.cs
- FrameworkElementFactory.cs
- WebControlsSection.cs
- ClientRolePrincipal.cs
- UInt16.cs
- Expression.DebuggerProxy.cs
- ServerIdentity.cs
- Bezier.cs
- AccessDataSourceWizardForm.cs
- ScaleTransform.cs
- AdjustableArrowCap.cs
- WebEventTraceProvider.cs
- CodeMemberProperty.cs
- ParameterBinding.cs
- File.cs
- ExpressionNormalizer.cs
- CheckoutException.cs
- SqlTrackingQuery.cs
- ErrorActivity.cs
- RoleManagerEventArgs.cs
- RowType.cs
- Compiler.cs
- IntellisenseTextBox.designer.cs
- Viewport2DVisual3D.cs
- GeneralTransform2DTo3DTo2D.cs
- TreeNodeCollectionEditor.cs
- SerialPinChanges.cs
- SortKey.cs
- WebUtil.cs
- OpenFileDialog.cs
- DescriptionAttribute.cs
- SecureUICommand.cs
- ECDiffieHellmanPublicKey.cs
- LockCookie.cs
- DashStyle.cs
- TaskScheduler.cs
- MulticastNotSupportedException.cs
- Rect.cs
- ElementsClipboardData.cs
- QilLiteral.cs
- DataSourceCacheDurationConverter.cs
- UpdateManifestForBrowserApplication.cs
- SHA1Managed.cs
- XPathArrayIterator.cs
- BuilderInfo.cs
- Matrix3DValueSerializer.cs
- ExpressionEditorSheet.cs
- SafePipeHandle.cs
- CopyOnWriteList.cs
- EditorPartChrome.cs
- TagPrefixInfo.cs
- DecodeHelper.cs
- XamlInt32CollectionSerializer.cs
- DataServiceOperationContext.cs
- TableLayoutSettings.cs
- OdbcException.cs
- SiteMapSection.cs
- ResourcesGenerator.cs
- BitmapDecoder.cs
- ObjectAssociationEndMapping.cs
- Model3DGroup.cs
- Timer.cs
- AuthenticationSection.cs
- TextEffectCollection.cs
- RTLAwareMessageBox.cs
- RegexCapture.cs
- TextBoxLine.cs
- UnmanagedBitmapWrapper.cs
- DefaultBindingPropertyAttribute.cs
- XmlDownloadManager.cs
- ComponentSerializationService.cs
- MethodBuilder.cs
- ObjectStateEntryDbDataRecord.cs
- Scripts.cs
- MarkupCompiler.cs
- EntityContainerRelationshipSet.cs
- RoutingUtilities.cs
- ProjectionCamera.cs
- Maps.cs