示例#1
0
 public CodeFileToken(string value, CodeFileTokenKind kind)
 {
     Value        = value;
     NavigateToId = null;
     Kind         = kind;
     DefinitionId = null;
 }
            public void AnnotateLink(string navigationId, CodeFileTokenKind kind)
            {
                int index = GetLastTokenIndex(kind);
                var last  = _tokens[index];

                last.NavigateToId = navigationId;
                _tokens[index]    = last;
            }
            /// <summary>
            /// Write the text representation of the given values followed by a
            /// newline, with indentation as appropriate.  This will force the
            /// next Write call to indent before anything else is written.
            /// </summary>
            /// <param name='format'>Format string.</param>
            /// <param name='args'>Optional arguments to the format string.</param>
            public void WriteLine(CodeFileTokenKind kind, string format, params object[] args)
            {
                Write(kind, format, args);
                Write(CodeFileTokenKind.Newline, Environment.NewLine);

                // Track that we just wrote a line so the next write operation
                // will indent first
                _isNewline = true;
            }
                /// <summary>
                /// Initializes a new instance of the WriterScope class.
                /// </summary>
                /// <param name='writer'>
                /// The IndentWriter containing the scope.
                /// </param>
                /// <param name='scopeStart'>Text starting the scope.</param>
                /// <param name='scopeEnd'>Text ending the scope.</param>
                /// <param name="newline">Whether to inject a newline.</param>
                /// <param name="kind">The kind of token to write.</param>
                public WriterScope(IndentWriter writer, string scopeStart, string scopeEnd, bool newline, CodeFileTokenKind kind)
                {
                    Debug.Assert(writer != null, "writer cannot be null!");
                    Debug.Assert(scopeStart != null, "scopeStart cannot be null!");
                    Debug.Assert(scopeEnd != null, "scopeEnd cannot be null!");

                    _writer = writer;
                    _writer.PushScope(newline, kind, scopeStart);
                    _scopeEnd = scopeEnd;
                    _kind     = kind;
                    _newline  = newline;
                }
 public void PushScope(bool newline, CodeFileTokenKind kind, string format, params object[] args)
 {
     if (newline)
     {
         WriteLine(kind, format, args);
     }
     else
     {
         Write(kind, format, args);
     }
     PushScope();
 }
            public void PopScope(bool newline, CodeFileTokenKind kind, string format, params object[] args)
            {
                PopScope();

                // Force the format string to be written on a new line, but
                // don't add an extra one if we just wrote a newline.
                if (!_isNewline && newline)
                {
                    WriteLine();
                }

                Write(kind, format, args);
            }
            /// <summary>
            /// Write the text representation of the given values with
            /// indentation as appropriate.
            /// </summary>
            /// <param name='format'>Format string.</param>
            /// <param name='args'>Optional arguments to the format string.</param>
            public void Write(CodeFileTokenKind kind, string format, params object[] args)
            {
                WriteIndentIfNeeded();

                // Only use AppendFormat if we have args so that we don't have
                // to escape curly brace literals used on their own.
                if (args?.Length > 0)
                {
                    format = string.Format(format, args);
                }

                Append(kind, format);
            }
示例#8
0
 public void Append(string value, CodeFileTokenKind kind)
 {
     Tokens.Add(new CodeFileToken(value, kind));
 }
 /// <summary>
 /// Create a writer scope that will indent until the scope is
 /// disposed and starts/ends the scope with the given text.  This
 /// is used like:
 ///     using (writer.Scope("{", "}"))
 ///     {
 ///         /* Write indented lines here */
 ///     }
 ///     /* Back to normal here */
 /// </summary>
 /// <param name='start'>Text starting the scope.</param>
 /// <param name='end'>Text ending the scope.</param>
 /// <param name="kind">The kind of token to use.</param>
 public IDisposable Scope(string start, string end, bool newline = true, CodeFileTokenKind kind = CodeFileTokenKind.Punctuation) =>
 /// <summary>
 /// Decrease the indent level after writing the text representation
 /// of the given values to the current line.  This would be used
 /// like:
 ///     myIndentWriter.PushScope("{");
 ///     /* Write indented lines here */
 ///     myIndentWriter.PopScope("}");
 /// </summary>
 /// <param name='format'>Format string.</param>
 /// <param name='args'>Optional arguments to the format string.</param>
 public void PopScope(CodeFileTokenKind kind, string format, params object[] args) =>
 PopScope(newline: true, kind, format, args);
 private void Append(CodeFileTokenKind kind, string text) =>
 _tokens.Add(new CodeFileToken(text, kind));