Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / Runtime / StringConcat.cs / 1305376 / StringConcat.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.ComponentModel; namespace System.Xml.Xsl.Runtime { ////// Efficiently concatenates strings when the number of string is not known beforehand, and /// yet it is common for only one string to be concatenated. StringBuilder is not good for /// this purpose, since it *always* allocates objects, even if only one string is appended. /// [EditorBrowsable(EditorBrowsableState.Never)] public struct StringConcat { private string s1, s2, s3, s4; private string delimiter; private ListstrList; int idxStr; /// /// Clear the result string. /// public void Clear() { this.idxStr = 0; this.delimiter = null; } ////// Gets or sets the string that delimits concatenated strings. /// public string Delimiter { get { return this.delimiter; } set { this.delimiter = value; } } ////// Return the number of concatenated strings, including delimiters. /// internal int Count { get { return this.idxStr; } } ////// Concatenate a new string to the result. /// public void Concat(string value) { Debug.Assert(value != null); if (this.delimiter != null && this.idxStr != 0) { // Add delimiter ConcatNoDelimiter(this.delimiter); } ConcatNoDelimiter(value); } ////// Get the result string. /// public string GetResult() { switch (this.idxStr) { case 0: return string.Empty; case 1: return this.s1; case 2: return string.Concat(this.s1, this.s2); case 3: return string.Concat(this.s1, this.s2, this.s3); case 4: return string.Concat(this.s1, this.s2, this.s3, this.s4); } return string.Concat(this.strList.ToArray()); } ////// Concatenate a new string to the result without adding a delimiter. /// internal void ConcatNoDelimiter(string s) { switch (this.idxStr) { case 0: this.s1 = s; break; case 1: this.s2 = s; break; case 2: this.s3 = s; break; case 3: this.s4 = s; break; case 4: // Calling Clear() is expensive, allocate a new List instead int capacity = (this.strList == null) ? 8 : this.strList.Count; ListstrList = this.strList = new List (capacity); strList.Add(this.s1); strList.Add(this.s2); strList.Add(this.s3); strList.Add(this.s4); goto default; default: this.strList.Add(s); break; } this.idxStr++; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.ComponentModel; namespace System.Xml.Xsl.Runtime { ////// Efficiently concatenates strings when the number of string is not known beforehand, and /// yet it is common for only one string to be concatenated. StringBuilder is not good for /// this purpose, since it *always* allocates objects, even if only one string is appended. /// [EditorBrowsable(EditorBrowsableState.Never)] public struct StringConcat { private string s1, s2, s3, s4; private string delimiter; private ListstrList; int idxStr; /// /// Clear the result string. /// public void Clear() { this.idxStr = 0; this.delimiter = null; } ////// Gets or sets the string that delimits concatenated strings. /// public string Delimiter { get { return this.delimiter; } set { this.delimiter = value; } } ////// Return the number of concatenated strings, including delimiters. /// internal int Count { get { return this.idxStr; } } ////// Concatenate a new string to the result. /// public void Concat(string value) { Debug.Assert(value != null); if (this.delimiter != null && this.idxStr != 0) { // Add delimiter ConcatNoDelimiter(this.delimiter); } ConcatNoDelimiter(value); } ////// Get the result string. /// public string GetResult() { switch (this.idxStr) { case 0: return string.Empty; case 1: return this.s1; case 2: return string.Concat(this.s1, this.s2); case 3: return string.Concat(this.s1, this.s2, this.s3); case 4: return string.Concat(this.s1, this.s2, this.s3, this.s4); } return string.Concat(this.strList.ToArray()); } ////// Concatenate a new string to the result without adding a delimiter. /// internal void ConcatNoDelimiter(string s) { switch (this.idxStr) { case 0: this.s1 = s; break; case 1: this.s2 = s; break; case 2: this.s3 = s; break; case 3: this.s4 = s; break; case 4: // Calling Clear() is expensive, allocate a new List instead int capacity = (this.strList == null) ? 8 : this.strList.Count; ListstrList = this.strList = new List (capacity); strList.Add(this.s1); strList.Add(this.s2); strList.Add(this.s3); strList.Add(this.s4); goto default; default: this.strList.Add(s); break; } this.idxStr++; } } } // 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
- XmlDocumentFragment.cs
- DataContext.cs
- SharedConnectionInfo.cs
- CodeSnippetStatement.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- ServiceDescription.cs
- ParserContext.cs
- FunctionNode.cs
- FixedBufferAttribute.cs
- CheckableControlBaseAdapter.cs
- DataGridViewColumnCollection.cs
- IResourceProvider.cs
- SetterBaseCollection.cs
- EntityContainer.cs
- TableCellCollection.cs
- ApplicationHost.cs
- PolicyManager.cs
- ProcessProtocolHandler.cs
- RouteData.cs
- Run.cs
- Image.cs
- ArrayList.cs
- UriParserTemplates.cs
- TableHeaderCell.cs
- XPathEmptyIterator.cs
- SqlMetaData.cs
- SpeechDetectedEventArgs.cs
- Content.cs
- _AcceptOverlappedAsyncResult.cs
- ListViewInsertEventArgs.cs
- AnnotationResourceCollection.cs
- StructuralObject.cs
- DocumentGridContextMenu.cs
- VirtualDirectoryMapping.cs
- NativeCppClassAttribute.cs
- TableParaClient.cs
- HtmlProps.cs
- PointHitTestResult.cs
- PackagePartCollection.cs
- DocumentApplicationJournalEntryEventArgs.cs
- RankException.cs
- TabControlAutomationPeer.cs
- HtmlEncodedRawTextWriter.cs
- AdjustableArrowCap.cs
- SourceChangedEventArgs.cs
- CodeDelegateCreateExpression.cs
- LinkButton.cs
- UnhandledExceptionEventArgs.cs
- SqlCachedBuffer.cs
- NamespaceList.cs
- ResourceSet.cs
- ContextDataSourceContextData.cs
- Stylesheet.cs
- TextPattern.cs
- TypeExtensionConverter.cs
- XamlTemplateSerializer.cs
- OrderByQueryOptionExpression.cs
- PrivilegedConfigurationManager.cs
- ConnectivityStatus.cs
- FileUtil.cs
- OleDbSchemaGuid.cs
- InstalledFontCollection.cs
- SessionPageStatePersister.cs
- WindowsRichEdit.cs
- HttpStreams.cs
- EditorAttribute.cs
- DesignTimeSiteMapProvider.cs
- PeerContact.cs
- PasswordTextContainer.cs
- ConfigUtil.cs
- NumericUpDownAccelerationCollection.cs
- DataDocumentXPathNavigator.cs
- AudioSignalProblemOccurredEventArgs.cs
- RectValueSerializer.cs
- XsltContext.cs
- WebScriptServiceHost.cs
- Cell.cs
- ObjectSet.cs
- BufferBuilder.cs
- SemaphoreSlim.cs
- XamlUtilities.cs
- EllipseGeometry.cs
- ObjectConverter.cs
- ObjectContext.cs
- IntMinMaxAggregationOperator.cs
- Rights.cs
- SqlErrorCollection.cs
- AppSettings.cs
- StatusBarPanel.cs
- XAMLParseException.cs
- xml.cs
- SecurityTraceRecordHelper.cs
- URI.cs
- SafeSecurityHandles.cs
- WorkflowQueuingService.cs
- PagedControl.cs
- FontSizeConverter.cs
- TextFormatterImp.cs
- CodeCommentStatementCollection.cs
- DoubleCollection.cs