Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CodeGeneratorOptions Class

Represents a set of options used by a code generator.

For a list of all members of this type, see CodeGeneratorOptions Members.

System.Object
   System.CodeDom.Compiler.CodeGeneratorOptions

[Visual Basic]
Public Class CodeGeneratorOptions
[C#]
public class CodeGeneratorOptions
[C++]
public __gc class CodeGeneratorOptions
[JScript]
public class CodeGeneratorOptions

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

CodeGeneratorOptions is passed to the code generation methods of an ICodeGenerator implementation to specify options used during code generation.

The IndentString property specifies the string to use for each spacing indentation. The BracingStyle property specifies the placement style for braces indicating the boundaries of code blocks. The ElseOnClosing property specifies whether to append an else, catch, or finally block, including brackets, at the closing line of each if or try block. The BlankLinesBetweenMembers property specifies whether to insert blank lines between members.

An ICodeGenerator implementation can provide custom code generation options which you can set or pass data to using the Item dictionary indexer, which a code generator can search through to locate additional code generation options.

Example

[Visual Basic] 
' Creates a new CodeGeneratorOptions.
Dim genOptions As New CodeGeneratorOptions()

' Sets a value indicating that the code generator should insert blank lines between type members.
genOptions.BlankLinesBetweenMembers = True

' Sets the style of bracing format to use: either "Block" to start a
' bracing block on the same line as the declaration of its container, or 
' "C" to start the bracing for the block on the following line.
genOptions.BracingStyle = "C"

' Sets a value indicating that the code generator should not append an else, 
' catch or finally block, including brackets, at the closing line of a preceeding if or try block.
genOptions.ElseOnClosing = False

' Sets the string to indent each line with.
genOptions.IndentString = "    "

' Uses the CodeGeneratorOptions indexer property to set an
' example object to the type's string-keyed ListDictionary.
' Custom ICodeGenerator implementations can use objects 
' in this dictionary to customize process behavior.
genOptions("CustomGeneratorOptionStringExampleID") = "BuildFlags: /A /B /C /D /E"

[C#] 
// Creates a new CodeGeneratorOptions.
CodeGeneratorOptions genOptions = new CodeGeneratorOptions();

// Sets a value indicating that the code generator should insert blank lines between type members.
genOptions.BlankLinesBetweenMembers = true;

// Sets the style of bracing format to use: either "Block" to start a
// bracing block on the same line as the declaration of its container, or 
// "C" to start the bracing for the block on the following line.
genOptions.BracingStyle = "C";

// Sets a value indicating that the code generator should not append an else, 
// catch or finally block, including brackets, at the closing line of a preceeding if or try block.
genOptions.ElseOnClosing = false;

// Sets the string to indent each line with.
genOptions.IndentString = "    ";

// Uses the CodeGeneratorOptions indexer property to set an
// example object to the type's string-keyed ListDictionary.
// Custom ICodeGenerator implementations can use objects 
// in this dictionary to customize process behavior.
genOptions["CustomGeneratorOptionStringExampleID"] = "BuildFlags: /A /B /C /D /E";            

[C++] 
// Creates a new CodeGeneratorOptions.
CodeGeneratorOptions* genOptions = new CodeGeneratorOptions();

// Sets a value indicating that the code generator should insert blank lines between type members.
genOptions->BlankLinesBetweenMembers = true;

// Sets the style of bracing format to use: either S"Block" to start a
// bracing block on the same line as the declaration of its container, or
// S"C" to start the bracing for the block on the following line.
genOptions->BracingStyle = S"C";

// Sets a value indicating that the code generator should not append an else,
// catch or finally block, including brackets, at the closing line of a preceeding if or try block.
genOptions->ElseOnClosing = false;

// Sets the String* to indent each line with.
genOptions->IndentString = S"    ";

// Uses the CodeGeneratorOptions indexer property to set an
// example Object* to the type's String*-keyed ListDictionary.
// Custom ICodeGenerator* implementations can use objects
// in this dictionary to customize process behavior.
genOptions->Item[S"CustomGeneratorOptionStringExampleID"] = S"BuildFlags: /A /B /C /D /E";

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom.Compiler

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeGeneratorOptions Members | System.CodeDom.Compiler Namespace

Show:
© 2014 Microsoft. All rights reserved.