Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Serializers / IndentedTextWriter.cs / 1305376 / IndentedTextWriter.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a writer implementation for Json format // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Serializers { using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; ///Writes the Json text in indented format. ////// There are many more methods implemented in previous versions /// of this file to handle more type and newline cases. /// internal sealed class IndentedTextWriter : TextWriter { ///writer to which Json text needs to be written private TextWriter writer; ///keeps track of the indentLevel private int indentLevel; ///keeps track of pending tabs private bool tabsPending; ///string representation of tab private string tabString; ////// Creates a new instance of IndentedTextWriter over the given text writer /// /// writer which IndentedTextWriter wraps public IndentedTextWriter(TextWriter writer) : base(CultureInfo.InvariantCulture) { this.writer = writer; this.tabString = " "; } ///Returns the Encoding for the given writer public override Encoding Encoding { get { return this.writer.Encoding; } } ///Returns the new line character public override string NewLine { get { return this.writer.NewLine; } } ///returns the current indent level public int Indent { get { return this.indentLevel; } set { Debug.Assert(value >= 0, "value >= 0"); if (value < 0) { value = 0; } this.indentLevel = value; } } ///Closes the underlying writer public override void Close() { // This is done to make sure we don't accidently close the underlying stream. // Since we don't own the stream, we should never close it. throw new NotImplementedException(); } ///Clears all the buffer of the current writer public override void Flush() { this.writer.Flush(); } ////// Writes the given string value to the underlying writer /// /// string value to be written public override void Write(string s) { this.OutputTabs(); this.writer.Write(s); } ////// Writes the given char value to the underlying writer /// /// char value to be written public override void Write(char value) { this.OutputTabs(); this.writer.Write(value); } ////// Writes the trimmed text if minimizeWhiteSpeace is set to true /// /// string value to be written public void WriteTrimmed(string text) { this.Write(text); } ///Writes the tabs depending on the indent level private void OutputTabs() { if (this.tabsPending) { for (int i = 0; i < this.indentLevel; i++) { this.writer.Write(this.tabString); } this.tabsPending = false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a writer implementation for Json format // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Serializers { using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; ///Writes the Json text in indented format. ////// There are many more methods implemented in previous versions /// of this file to handle more type and newline cases. /// internal sealed class IndentedTextWriter : TextWriter { ///writer to which Json text needs to be written private TextWriter writer; ///keeps track of the indentLevel private int indentLevel; ///keeps track of pending tabs private bool tabsPending; ///string representation of tab private string tabString; ////// Creates a new instance of IndentedTextWriter over the given text writer /// /// writer which IndentedTextWriter wraps public IndentedTextWriter(TextWriter writer) : base(CultureInfo.InvariantCulture) { this.writer = writer; this.tabString = " "; } ///Returns the Encoding for the given writer public override Encoding Encoding { get { return this.writer.Encoding; } } ///Returns the new line character public override string NewLine { get { return this.writer.NewLine; } } ///returns the current indent level public int Indent { get { return this.indentLevel; } set { Debug.Assert(value >= 0, "value >= 0"); if (value < 0) { value = 0; } this.indentLevel = value; } } ///Closes the underlying writer public override void Close() { // This is done to make sure we don't accidently close the underlying stream. // Since we don't own the stream, we should never close it. throw new NotImplementedException(); } ///Clears all the buffer of the current writer public override void Flush() { this.writer.Flush(); } ////// Writes the given string value to the underlying writer /// /// string value to be written public override void Write(string s) { this.OutputTabs(); this.writer.Write(s); } ////// Writes the given char value to the underlying writer /// /// char value to be written public override void Write(char value) { this.OutputTabs(); this.writer.Write(value); } ////// Writes the trimmed text if minimizeWhiteSpeace is set to true /// /// string value to be written public void WriteTrimmed(string text) { this.Write(text); } ///Writes the tabs depending on the indent level private void OutputTabs() { if (this.tabsPending) { for (int i = 0; i < this.indentLevel; i++) { this.writer.Write(this.tabString); } this.tabsPending = false; } } } } // 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
- QilStrConcatenator.cs
- Journal.cs
- WhitespaceSignificantCollectionAttribute.cs
- ConsoleCancelEventArgs.cs
- DiscriminatorMap.cs
- AccessKeyManager.cs
- CodeSnippetStatement.cs
- FormsAuthenticationConfiguration.cs
- BindingCollection.cs
- SmiConnection.cs
- Effect.cs
- EdmItemCollection.cs
- TcpClientChannel.cs
- UriScheme.cs
- SynchronizedKeyedCollection.cs
- SqlUnionizer.cs
- ConfigsHelper.cs
- MsmqIntegrationReceiveParameters.cs
- SiteMapNodeItemEventArgs.cs
- ObfuscateAssemblyAttribute.cs
- ObjectQuery_EntitySqlExtensions.cs
- Size3D.cs
- OSFeature.cs
- XmlSchemaType.cs
- ParserHooks.cs
- ByteStreamGeometryContext.cs
- EditorZone.cs
- VScrollBar.cs
- Rotation3D.cs
- ProcessHostMapPath.cs
- ListViewItem.cs
- Renderer.cs
- DbException.cs
- DataFieldConverter.cs
- FixedSOMPageConstructor.cs
- ProtocolInformationWriter.cs
- RealProxy.cs
- MenuItemBinding.cs
- ToolStripLocationCancelEventArgs.cs
- SafeNativeMethods.cs
- ConditionChanges.cs
- XmlCustomFormatter.cs
- UserInitiatedRoutedEventPermission.cs
- EntityContainerEmitter.cs
- DrawingContextDrawingContextWalker.cs
- XmlDocumentFragment.cs
- DesignTimeParseData.cs
- DependencyProperty.cs
- Environment.cs
- ObjectTag.cs
- JsonSerializer.cs
- ToolboxItemAttribute.cs
- StylusTip.cs
- X509CertificateCollection.cs
- TempEnvironment.cs
- DbParameterHelper.cs
- Crypto.cs
- DateTimeOffsetStorage.cs
- AnonymousIdentificationSection.cs
- StoreItemCollection.cs
- VersionConverter.cs
- InfoCardProofToken.cs
- IDQuery.cs
- ServerValidateEventArgs.cs
- LoggedException.cs
- LinqDataView.cs
- ResumeStoryboard.cs
- TextSerializer.cs
- InteropExecutor.cs
- ReadOnlyDataSource.cs
- KeyFrames.cs
- HttpCacheParams.cs
- smtppermission.cs
- Comparer.cs
- DataGridViewDataConnection.cs
- SemanticValue.cs
- XmlSortKeyAccumulator.cs
- CodeGenerator.cs
- QueryCursorEventArgs.cs
- GB18030Encoding.cs
- ValidationErrorCollection.cs
- XPathNavigator.cs
- TextContainerChangedEventArgs.cs
- BuiltInExpr.cs
- SaveFileDialog.cs
- EventQueueState.cs
- SqlVersion.cs
- IsolatedStorageSecurityState.cs
- MenuItemBinding.cs
- SiteMapHierarchicalDataSourceView.cs
- CodePageUtils.cs
- SocketElement.cs
- ParameterReplacerVisitor.cs
- WebPart.cs
- XmlSchemaObjectTable.cs
- InfoCardXmlSerializer.cs
- DragEventArgs.cs
- DataSourceExpressionCollection.cs
- Dump.cs
- HttpErrorTraceRecord.cs