sealed class
|
SourceCodeWriter
|
extends
|
Disposable
|
||
implements
|
IFlushable
|
The maximum number of columns (inclusive indentation) to write per source code line before emitting an automatic line break.
public
property
|
AutoBreakColumns
{
get
}
|
||
type
|
int32
|
||
value
|
|
The maximum number of columns before auto-breaking occurs. |
Returns the current column number (zero-based).
public
property
|
Column
{
get
}
|
||
type
|
int32
|
||
value
|
|
The current column number. |
The current line indent level.
public
property
|
Indent
{
get
set
}
|
||
type
|
int32
|
||
value
|
|
The current line indent level. |
The string token that represents a single indentation level.
public
property
|
IndentToken
{
get
}
|
||
type
|
string
|
||
value
|
|
The indent token string. |
Is the current line fresh (i.e. no characters have been output yet)?
public
property
|
IsFreshLine
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
the
current
line
is
fresh,
false
if
not. |
Returns the lifecycle state of this object.
public
virtual
property
|
LifecycleState
{
get
}
|
||
type
|
LifecycleState
|
||
value
|
The lifecycle state. | ||
inherited
|
Disposable.LifecycleState
|
Returns the current line number (zero-based).
public
property
|
Line
{
get
}
|
||
type
|
int32
|
||
value
|
|
The current line number. |
public
property
|
LinePrefix
{
get
set
}
|
||
type
|
string
|
||
value
|
Creates a new instance of SourceCodeWriter.
public
constructor
|
SourceCodeWriter
([Owner]
ITextStream stream,
int32 autoBreakColumns = 100,
string indentToken = " ",
LineEnding newlineToken = LineEnding.Native)
|
||
params
|
stream
|
[not-null]
|
The output text stream. |
autoBreakColumns
|
[>=0]
|
The maximum number of columns (inclusive indentation) to write per source code line before emitting an automatic line break. | |
indentToken
|
[not-null]
|
The string token that represents a single indentation level. Defaults to two whitespace characters. | |
newlineToken
|
The string token that represents a line break. Defaults to Native. |
Acquires a strong reference to this disposable object.
[OwnerReturn, ThreadSafe]
|
||||
public
method
|
AcquireTry
()
|
|||
type
|
IDisposable
|
|||
returns
|
this
if
a
new
strong
reference
has
been
acquired,
null
if
this
object
is
already
being
disposed.
|
|||
inherited
|
Disposable.AcquireTry
|
Remarks:
The object will not be actually disposed by calls to Dispose when there is at least one strong reference left. Code that calls the AcquireTry method is responsible for calling the Dispose method accordingly.
This method is not intended to be used in performance-critical code. It should only be used to high-level resource management.
Begins
a
nested
pair
of
angle
brackets:
<
>
public
method
|
Angle
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
CloseBegins
a
nested
pair
of
braces:
(
)
public
method
|
Braces
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
CloseBegins
a
nested
pair
of
square
brackets:
[ ]
public
method
|
Brackets
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
CloseCloses the current nested tag by writing the end tag that has been specified by the corresponding call to Open.
public
method
|
Close
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
OpenWrites
a
token:
':'
public
method
|
Colon
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
TokenWrites
a
token:
','
public
method
|
Comma
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
TokenBegins
a
nested
pair
of
curly
braces:
{
}
public
method
|
Curly
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
CloseReleases all resources held by this object if there are no more strong references to it, decrements the reference counter by one otherwise.
[Dispose, OwnerThis, ThreadSafe]
|
||||
public
method
|
Dispose
()
|
|||
inherited
|
Disposable.Dispose
|
Remarks:
The Dispose method silently returns if the object has already been disposed.
Flushes all cached data.
public
method
|
Flush
()
|
||
implements
|
IFlushable.Flush
|
Remarks:
Performing a flush may result in I/O work. Depending on the semantics of the implementing class, this work may need to be wrapped in special Begin / End method calls. See the documentation of the implementing classes for details.
In case this object represents a read-only resource, calling the Flush method has no effect.
Decreases the indentation level.
public
method
|
IndentLeft
(int32 n = 1)
|
||
type
|
SourceCodeWriter
|
||
params
|
n
|
[>=0]
|
Number of indentation levels to remove. |
returns
|
|
this |
Remarks:
The new indentation level will be taken into account when the next line break is emitted.
Increases the indentation level.
public
method
|
IndentRight
(int32 n = 1)
|
||
type
|
SourceCodeWriter
|
||
params
|
n
|
[>=0]
|
Number of indentation levels to add. |
returns
|
|
this |
Remarks:
The new indentation level will be taken into account when the next line break is emitted.
Appends a line break and begins a fresh line.
public
method
|
Newline
(int32 n = 1)
|
||
type
|
SourceCodeWriter
|
||
params
|
n
|
[>=0]
|
Number of line breaks to emit. |
returns
|
|
this |
Writes the given token, followed by a line break.
public
method
|
Newline
(string token)
|
||
type
|
SourceCodeWriter
|
||
params
|
token
|
[not-null]
|
The string token to write. |
returns
|
|
this |
Ensures that the current write cursor is located at the beginning of a fresh source code line.
public
method
|
NewlineIfNotFresh
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
Remarks:
This method emits a line break when characters have been written to the current code line.
Writes a node that itself is producing source code.
public
method
|
Node
(ICodeOutput node,
Context context)
|
||
type
|
SourceCodeWriter
|
||
params
|
node
|
[not-null]
|
The source code producing node. |
context
|
[not-null]
|
Context object. | |
returns
|
|
this |
Begins a nested tag by writing the opening tag now and the end tag when the corresponding call to Close is made.
public
method
|
Open
(string openTag,
string endTag,
bool autoBreak = true)
|
||
type
|
SourceCodeWriter
|
||
params
|
openTag
|
[not-null]
|
The opening tag. |
endTag
|
[not-null]
|
The end tag. | |
autoBreak
|
true
if
openTag
and
endTag
count
for
auto-breaking
lines,
false
if
not
(i.e.
they
represent
markup
and
no
actual
content).
|
||
returns
|
|
this |
See also:
CloseWrites
a
token:
'.'
public
method
|
Period
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
TokenWrites
a
token:
'.'
public
method
|
Semicolon
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
See also:
TokenBegins
an
XML
element
pair:
<name>
</name>
public
method
|
Tag
(string name,
bool autoBreak = true)
|
||
type
|
SourceCodeWriter
|
||
params
|
name
|
[not-empty]
|
The tag name. |
autoBreak
|
true
if
name
counts
for
auto-breaking
lines,
false
if
not
(i.e.
they
represent
markup
and
no
actual
content).
|
||
returns
|
|
this |
See also:
CloseWrites the given text.
public
method
|
Text
(string text,
TrimBehaviour behaviour = TrimBehaviour.WhitespaceAndLineBreak)
|
||
type
|
SourceCodeWriter
|
||
params
|
text
|
[not-null]
|
The text to write. |
behaviour
|
The trim behaviour to use. Defaults to WhitespaceAndLineBreak. | ||
returns
|
|
this |
Remarks:
The text will be split at the whitespaces and the resulting tokens will be emitted in order.
Writes a token on the current source code line.
public
method
|
Token
(string token)
|
||
type
|
SourceCodeWriter
|
||
params
|
token
|
[not-null]
|
The token to write. |
returns
|
|
this |
Remarks:
A token is considered to be atomic, i.e. it will never be split because of automatic line breaks.
See also:
ColonWrites a token on the current source code line.
public
method
|
Token
(char token,
int32 n = 1)
|
||
type
|
SourceCodeWriter
|
||
params
|
token
|
The token character to write. | |
n
|
Number
of
times
to
repeat
token.
Defaults
to
1 .
|
||
returns
|
|
this |
Remarks:
A token is considered to be atomic, i.e. it will never be split because of automatic line breaks.
Underlines the current line using the given character.
public
method
|
Underline
(char character = ''-'')
|
||
type
|
SourceCodeWriter
|
||
params
|
character
|
The
underline
character.
Defaults
to
'-' . |
|
returns
|
|
this |
Remarks:
A line break is emitted after the underline. If the current line is still fresh, the method silently returns.
Writes a whitespace token.
public
method
|
White
()
|
||
type
|
SourceCodeWriter
|
||
returns
|
|
this |
Will an automatic line-break occur when the next token is output?
public
method
|
WillAutoBreak
(int32 n = 1)
|
||
type
|
bool
|
||
params
|
n
|
[>=0]
|
Length of next token, in characters. |
returns
|
true
if
a
line-break
will
occur,
false
if
not. |