Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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 } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// 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 } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TrustLevelCollection.cs
- DesigntimeLicenseContextSerializer.cs
- NullableLongAverageAggregationOperator.cs
- PrivilegeNotHeldException.cs
- XsltInput.cs
- QilExpression.cs
- HitTestDrawingContextWalker.cs
- SystemWebSectionGroup.cs
- MediaTimeline.cs
- PropertyDescriptorCollection.cs
- FaultDescriptionCollection.cs
- MergePropertyDescriptor.cs
- MarkerProperties.cs
- DeadCharTextComposition.cs
- SQLMembershipProvider.cs
- SupportedAddressingMode.cs
- LinkDesigner.cs
- AsnEncodedData.cs
- PageThemeBuildProvider.cs
- CssTextWriter.cs
- ClickablePoint.cs
- MarginsConverter.cs
- _NtlmClient.cs
- DataServiceRequestException.cs
- Pkcs7Recipient.cs
- PassportIdentity.cs
- WebPartCatalogCloseVerb.cs
- WebSysDescriptionAttribute.cs
- SchemaTableOptionalColumn.cs
- RtfControlWordInfo.cs
- XNameConverter.cs
- ArgumentDesigner.xaml.cs
- Int64AnimationBase.cs
- CommandID.cs
- Int32Converter.cs
- DataServiceQueryContinuation.cs
- Message.cs
- Message.cs
- DragCompletedEventArgs.cs
- Buffer.cs
- SafeWaitHandle.cs
- HeaderedContentControl.cs
- WebPartTransformer.cs
- TextFormatter.cs
- BamlLocalizableResource.cs
- SimpleHandlerFactory.cs
- NavigateUrlConverter.cs
- WhileDesigner.cs
- DefaultTraceListener.cs
- ToolStripScrollButton.cs
- DeclarationUpdate.cs
- FormParameter.cs
- FormViewCommandEventArgs.cs
- PanelStyle.cs
- ContentControl.cs
- PolicyDesigner.cs
- PropertyMetadata.cs
- EasingKeyFrames.cs
- StreamGeometry.cs
- TableCellCollection.cs
- SkewTransform.cs
- DynamicDocumentPaginator.cs
- DetailsViewUpdateEventArgs.cs
- basecomparevalidator.cs
- TreeIterators.cs
- BuildManagerHost.cs
- sqlser.cs
- ResourceCategoryAttribute.cs
- WebReferencesBuildProvider.cs
- DynamicActionMessageFilter.cs
- MobileUserControl.cs
- ItemCollection.cs
- WmlMobileTextWriter.cs
- WebPartHeaderCloseVerb.cs
- VirtualizedItemPattern.cs
- Rect3DConverter.cs
- SafeNativeMethods.cs
- ManifestResourceInfo.cs
- StrongNameKeyPair.cs
- StringResourceManager.cs
- WebPartDisplayModeCollection.cs
- SqlCommandSet.cs
- WindowsRichEdit.cs
- Clause.cs
- TrackingDataItemValue.cs
- MobileListItemCollection.cs
- OleDbConnectionInternal.cs
- CallTemplateAction.cs
- Messages.cs
- RequestSecurityTokenResponse.cs
- DataGridItemEventArgs.cs
- NavigationCommands.cs
- LoginName.cs
- XPathCompileException.cs
- AssemblyResolver.cs
- BaseDataBoundControl.cs
- StringAnimationUsingKeyFrames.cs
- TaiwanLunisolarCalendar.cs
- DataSourceControlBuilder.cs
- MetadataArtifactLoaderCompositeResource.cs