Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Misc / ConfigPathUtility.cs / 1 / ConfigPathUtility.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration {
#if CONFIGPATHUTILITY_SYSTEMWEB
using Debug=System.Web.Util.Debug;
#endif
internal static class ConfigPathUtility {
private const char SeparatorChar = '/';
//
// A configPath is valid if
// * It does not start or end with a '/'
// * It is not null or empty, except in the case of the root configuration record
// * It does not contain '\'
// * It does not contain a path component equal to "." or ".."
//
// The checks for '\', ".", and ".." are not strictly necessary, but their presence
// could lead to problems for configuration hosts.
//
static internal bool IsValid(string configPath) {
if (String.IsNullOrEmpty(configPath)) {
return false;
}
int start = -1;
for (int examine = 0; examine <= configPath.Length; examine++) {
char ch;
if (examine < configPath.Length) {
ch = configPath[examine];
}
else {
ch = SeparatorChar;
}
// backslash disallowed
if (ch == '\\') {
return false;
}
if (ch == SeparatorChar) {
// double slash disallowed
// note this check also purposefully catches starting and ending slash
if (examine == start + 1) {
return false;
}
// "." disallowed
if (examine == start + 2 && configPath[start + 1] == '.') {
return false;
}
// ".." disallowed
if (examine == start + 3 && configPath[start + 1] == '.' && configPath[start + 2] == '.') {
return false;
}
start = examine;
}
}
return true;
}
#if !CONFIGPATHUTILITY_SYSTEMWEB
static internal string Combine(string parentConfigPath, string childConfigPath) {
Debug.Assert(String.IsNullOrEmpty(parentConfigPath) || IsValid(parentConfigPath), "String.IsNullOrEmpty(parentConfigPath) || IsValid(parentConfigPath)");
Debug.Assert(String.IsNullOrEmpty(childConfigPath) || IsValid(childConfigPath), "String.IsNullOrEmpty(childConfigPath) || IsValid(childConfigPath)");
if (String.IsNullOrEmpty(parentConfigPath)) {
return childConfigPath;
}
if (String.IsNullOrEmpty(childConfigPath)) {
return parentConfigPath;
}
return parentConfigPath + "/" + childConfigPath;
}
static internal string[] GetParts(string configPath) {
Debug.Assert(IsValid(configPath), "IsValid(configPath)");
string[] parts = configPath.Split(SeparatorChar);
return parts;
}
//
// Return the last part of a config path, e.g.
// GetName("MACHINE/WEBROOT/Default Web Site/app") == "app"
//
static internal string GetName(string configPath) {
Debug.Assert(String.IsNullOrEmpty(configPath) || IsValid(configPath), "String.IsNullOrEmpty(configPath) || IsValid(configPath)");
if (String.IsNullOrEmpty(configPath)) {
return configPath;
}
int index = configPath.LastIndexOf('/');
if (index == -1) {
return configPath;
}
Debug.Assert(index != configPath.Length - 1);
return configPath.Substring(index + 1);
}
#endif
// Avoid unused code warning in System.Configuration by including functions in assembly-specific #defines
#if CONFIGPATHUTILITY_SYSTEMWEB
static internal string GetParent(string configPath) {
Debug.Assert(String.IsNullOrEmpty(configPath) || IsValid(configPath), "String.IsNullOrEmpty(configPath) || IsValid(configPath)");
if (String.IsNullOrEmpty(configPath)) {
return null;
}
string parentConfigPath;
int lastSlash = configPath.LastIndexOf(SeparatorChar);
if (lastSlash == -1) {
parentConfigPath = null;
}
else {
parentConfigPath = configPath.Substring(0, lastSlash);
}
return parentConfigPath;
}
#endif
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TransformGroup.cs
- SamlSubject.cs
- TimeSpanSecondsConverter.cs
- MailWriter.cs
- TemplatedWizardStep.cs
- Event.cs
- Knowncolors.cs
- RectAnimation.cs
- SubMenuStyleCollection.cs
- ColumnMapProcessor.cs
- ListBoxAutomationPeer.cs
- ObjectTypeMapping.cs
- RootDesignerSerializerAttribute.cs
- SplitterDesigner.cs
- ListViewCancelEventArgs.cs
- XmlHierarchicalDataSourceView.cs
- SchemaCollectionPreprocessor.cs
- OutOfProcStateClientManager.cs
- UInt16.cs
- FontFamily.cs
- TimeoutConverter.cs
- TableSectionStyle.cs
- NumericUpDown.cs
- ContactManager.cs
- SamlDelegatingWriter.cs
- InheritanceContextHelper.cs
- MissingSatelliteAssemblyException.cs
- DataRecord.cs
- DetailsViewPagerRow.cs
- StrongNameIdentityPermission.cs
- DataSourceBooleanViewSchemaConverter.cs
- UnsafeNativeMethods.cs
- SerializationInfo.cs
- ContainerParaClient.cs
- ProcessHostFactoryHelper.cs
- NodeFunctions.cs
- Function.cs
- ISAPIRuntime.cs
- MobilePage.cs
- IssuanceTokenProviderBase.cs
- CheckBox.cs
- TCPListener.cs
- XPathNodeIterator.cs
- AttributeData.cs
- Int32Rect.cs
- MetadataPropertyAttribute.cs
- GPStream.cs
- TimeSpanStorage.cs
- Translator.cs
- ArgIterator.cs
- StoragePropertyMapping.cs
- NativeDirectoryServicesQueryAPIs.cs
- WSHttpSecurityElement.cs
- WaitForChangedResult.cs
- ScriptReference.cs
- InternalConfirm.cs
- Root.cs
- SqlUtils.cs
- FactoryGenerator.cs
- PathGeometry.cs
- NativeWrapper.cs
- TransactionManager.cs
- HostAdapter.cs
- MarshalByValueComponent.cs
- DataServiceEntityAttribute.cs
- ClientRolePrincipal.cs
- EnvironmentPermission.cs
- SQLInt16Storage.cs
- EntityCommandDefinition.cs
- HtmlInputPassword.cs
- RNGCryptoServiceProvider.cs
- SamlSerializer.cs
- NativeMethods.cs
- RowSpanVector.cs
- CngAlgorithm.cs
- ToolboxItem.cs
- CacheVirtualItemsEvent.cs
- CompareInfo.cs
- FormView.cs
- TableLayoutCellPaintEventArgs.cs
- CellPartitioner.cs
- DeadCharTextComposition.cs
- EncryptedPackageFilter.cs
- SiteMapNodeCollection.cs
- RedistVersionInfo.cs
- AttributeEmitter.cs
- SoapFault.cs
- DataPointer.cs
- IOThreadTimer.cs
- SafeIUnknown.cs
- NavigationWindowAutomationPeer.cs
- XpsLiterals.cs
- TextProviderWrapper.cs
- WindowsListViewGroup.cs
- TimeZone.cs
- HttpRuntime.cs
- XmlCompatibilityReader.cs
- cookiecollection.cs
- __FastResourceComparer.cs
- HashFinalRequest.cs