Code:
/ DotNET / DotNET / 8.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
- TextModifier.cs
- SatelliteContractVersionAttribute.cs
- dbenumerator.cs
- List.cs
- XPathParser.cs
- ObjectViewQueryResultData.cs
- ListViewCancelEventArgs.cs
- XPathCompileException.cs
- TextDecorationLocationValidation.cs
- MetadataUtilsSmi.cs
- _ProxyRegBlob.cs
- Assert.cs
- CTreeGenerator.cs
- WorkflowHostingResponseContext.cs
- XamlPoint3DCollectionSerializer.cs
- SQLInt16Storage.cs
- OdbcErrorCollection.cs
- ClientConfigPaths.cs
- ObjectDataSourceView.cs
- PropertyCondition.cs
- TableHeaderCell.cs
- OrderingQueryOperator.cs
- XmlSchemaComplexType.cs
- SetMemberBinder.cs
- WebPartManager.cs
- WebPartConnectionsCancelVerb.cs
- ValidationErrorCollection.cs
- PagerSettings.cs
- SecUtil.cs
- PackageFilter.cs
- MatrixTransform3D.cs
- ProviderConnectionPointCollection.cs
- AsyncCallback.cs
- FunctionNode.cs
- KernelTypeValidation.cs
- ShaderEffect.cs
- EventArgs.cs
- QilDataSource.cs
- ZipIOLocalFileDataDescriptor.cs
- WorkflowViewManager.cs
- UshortList2.cs
- TreeNodeStyleCollection.cs
- NumberFunctions.cs
- VectorCollection.cs
- DeploymentExceptionMapper.cs
- File.cs
- StylusPoint.cs
- SchemaAttDef.cs
- Sql8ConformanceChecker.cs
- ChineseLunisolarCalendar.cs
- SyndicationElementExtension.cs
- SemanticValue.cs
- WCFBuildProvider.cs
- XmlSchemaAttribute.cs
- ToolStripGrip.cs
- SqlFunctions.cs
- ObjectViewFactory.cs
- ToolbarAUtomationPeer.cs
- NavigatorInput.cs
- FormatSettings.cs
- control.ime.cs
- TextChangedEventArgs.cs
- XmlAggregates.cs
- ScriptReference.cs
- ProcessModule.cs
- SiteMapNodeItemEventArgs.cs
- TextDecorationCollection.cs
- Pen.cs
- ResourceType.cs
- JapaneseCalendar.cs
- HostExecutionContextManager.cs
- CompiledRegexRunnerFactory.cs
- RootBrowserWindowProxy.cs
- HtmlToClrEventProxy.cs
- DataListGeneralPage.cs
- DesignerVerbCollection.cs
- coordinator.cs
- TypeLoadException.cs
- DispatcherFrame.cs
- ConfigUtil.cs
- SqlParameterizer.cs
- CapabilitiesPattern.cs
- ListViewSortEventArgs.cs
- ButtonBaseAutomationPeer.cs
- DisplayMemberTemplateSelector.cs
- SqlConnectionStringBuilder.cs
- SiteMapHierarchicalDataSourceView.cs
- PolyBezierSegment.cs
- SetterBaseCollection.cs
- ImpersonationContext.cs
- TransformDescriptor.cs
- TogglePattern.cs
- DecoderExceptionFallback.cs
- LineProperties.cs
- GPPOINT.cs
- TdsParserHelperClasses.cs
- OutputWindow.cs
- ProtocolViolationException.cs
- GlobalizationAssembly.cs
- ToolStripSeparator.cs