Export (0) Print
Expand All

CodeGeneratorOptions Class

Represents a set of options used by a code generator.

System.Object
  System.CodeDom.Compiler.CodeGeneratorOptions

Namespace:  System.CodeDom.Compiler
Assembly:  System (in System.dll)

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public class CodeGeneratorOptions

The CodeGeneratorOptions type exposes the following members.

  NameDescription
Public methodCodeGeneratorOptionsInitializes a new instance of the CodeGeneratorOptions class.
Top

  NameDescription
Public propertyBlankLinesBetweenMembersGets or sets a value indicating whether to insert blank lines between members.
Public propertyBracingStyleGets or sets the style to use for bracing.
Public propertyElseOnClosingGets or sets a value indicating whether to append an else, catch, or finally block, including brackets, at the closing line of each previous if or try block.
Public propertyIndentStringGets or sets the string to use for indentations.
Public propertyItemGets or sets the object at the specified index.
Public propertyVerbatimOrderGets or sets a value indicating whether to generate members in the order in which they occur in member collections.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote

This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands and Inheritance Demands.

// 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";            

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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