CodeWriter class

namespace: Serenity.Reflection   assemblySerenity.Net.Core

Used to write formatted code to a string builder.

public class CodeWriter

Public Members

name description
CodeWriter(…) Initializes a new instance of the CodeWriter class. (3 constructors)
AllowUsing { get; set; } Gets sets function that determines if a namespace is allowed to be added to the local usings
BraceOnSameLine { get; set; } Whether to put opening brace on the same line.
Builder { get; } Gets internal string builder
CurrentNamespace { get; set; } Gets / sets current namespace
FileComment { get; set; } Gets / sets file comment
GlobalUsings { get; set; } Gets / sets global usings hash set
IsCSharp { get; set; } Gets / sets if the code writer is used for generating C# code.
LocalUsings { get; } Gets / sets local usings hash set
Tab { get; } Gets tab string
Append(…) Appends text to internal string builder (2 methods)
AppendLine() Appends a line to internal string builder
AppendLine(…) Appends a line to internal string builder
Block(…) Increases indent, runs the insideBlock and decreases indent back.
DecreaseIndent() Decreases indenting by tab size
EndBrace(…) Decreases indent and closes the brace
InBrace(…) Adds a brace, increases indent, runs the inside block, decreases indent back, closes the brace.
IncreaseIndent() Increases indenting using tab string
Indent() Appends current indent
Indented(…) Appends current indent and the specified string
IndentedLine(…) Appends current indent, the specified string, and a new line.
IndentedMultiLine(…) Appends each of the text's lines with current indent, and a new line.
InNamespace(…) Executes action by opening namespace if it is not null or empty
Insert(…) Inserts string to internal string builder
IsUsing(…) Returns true if the namespace is in list of usings.
ShortTypeName(…) Tries to add namespace (3 methods)
StartBrace() Adds a brace, increases indent.
override ToString() Returns string representation of internal string builder, including file comment and any local usings if any
Using(…) Returns true if the namespace is in list of usings. If AllowUsing callback is null or returns true, or force is true, this may add it to the list of local usings. (2 methods)
static IsCSKeyword(…) Determines is Type is a C# primitive keyword
static ToCSKeyword(…) Converts primitive class to C# keyword if given class is not a primitive class returns null.

See Also