Skip to content

CodeWriter class

namespace: Serenity.Reflection   assemblySerenity.Net.Core

Used to write formatted code to a string builder.

public class CodeWriter
parameter description
sb The sb.
tabSize Number of spaces.

Public Members

name description
CodeWriter(…) Used to write formatted code to a string builder. (3 constructors)
AllowUsing { get; set; } Gets sets function that determines if a namespace is allowed to be added to the local usings
AutoGeneratedComment { get; set; } Gets or sets a value indicating whether to add an auto-generated comment at the top of the generated code.
AutoGeneratedCommentText { get; set; } Gets or sets the text of the auto-generated comment to be added at the top of the generated code. The default value is "// ".
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
FileScopedNamespaces { get; set; } Use a file scoped namespace instead. Can only be used with one namespace per file.
GlobalUsings { get; set; } Gets / sets global usings hash set
Indentation { get; } Gets current indentation string
IsCSharp { get; set; } Gets / sets if the code writer is used for generating C# code.
LocalUsings { get; } Gets / sets local usings hash set
PragmaSuppressions { get; } Gets the set of pragma warning suppressions to be added at the top of the generated code.
SuppressMissingXmlCommentWarning { get; set; } Gets or sets a value indicating whether to suppress the CS1591 warning for missing XML comments in the generated code. When set to true, the CS1591 warning will be added to the set of pragma warning suppressions; when set to false, it will be removed from the set of pragma warning suppressions.
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(…) Returns the short type name for the given namespace and type name, adding the namespace to the local usings if possible. (2 methods)
ShortTypeRef(…) Converts a data type with a namespace to a data type without the namespace if its namespace is in the allowed usings, otherwise returns the full name. This can handle nullables, C# keywords, and generics to some extent. See IsCSharp if you are using this for C#.
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 the list of usings. If the AllowUsing callback is null or returns true, or force is true, this may add it to the list of local usings. (2 methods)
static readonly SafeSetOfUsings List of usings that can be safely used during code generation without causing type name clashes
static IsCSKeyword(…) Determines whether the given type name is a C# primitive keyword.
static IsJSKeyword(…) Returns true if the identifier is a reserved JavaScript keyword.
static ToCSKeyword(…) Converts a primitive class name to its C# keyword. If the given class is not a primitive class, returns null.

Remarks

Initializes a new instance of the CodeWriter class.

See Also