CodeGenerator 類別

定義

提供 ICodeGenerator 介面的範例實作。Provides an example implementation of the ICodeGenerator interface. 這個類別是抽象的。This class is abstract.

public ref class CodeGenerator abstract : System::CodeDom::Compiler::ICodeGenerator
public abstract class CodeGenerator : System.CodeDom.Compiler.ICodeGenerator
type CodeGenerator = class
    interface ICodeGenerator
Public MustInherit Class CodeGenerator
Implements ICodeGenerator
繼承
CodeGenerator
衍生
實作

備註

這是一個實用的基類, 可供程式碼產生器衍生自。This is a useful base class for code generators to derive from. 程式碼產生器可以根據程式碼檔物件模型 (CodeDOM) 圖表的結構, 轉譯特定語言的原始程式碼。Code generators are capable of rendering source code in a specific language according to the structure of a Code Document Object Model (CodeDOM) graph. 這個類別提供許多函式和方法, 可從 CodeDOM 圖表產生特定類型的程式碼。This class provides many functions and methods to generate specific types of code from a CodeDOM graph.

注意

此類別包含套用至所有成員之類別層級的連結要求和繼承要求。This class contains a link demand and an inheritance demand at the class level that applies to all members. 當立即呼叫端或衍生類別沒有完全信任許可權時,就會擲回。SecurityExceptionA 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.

建構函式

CodeGenerator()

初始化 CodeGenerator 類別的新執行個體。Initializes a new instance of the CodeGenerator class.

屬性

CurrentClass

取得目前類別的程式碼類型宣告。Gets the code type declaration for the current class.

CurrentMember

取得類別的目前成員。Gets the current member of the class.

CurrentMemberName

取得目前成員名稱。Gets the current member name.

CurrentTypeName

取得目前類別的名稱。Gets the current class name.

Indent

取得或設定縮排每個縮排層次的空格數量。Gets or sets the amount of spaces to indent each indentation level.

IsCurrentClass

取得值,指出目前產生的物件是否為類別。Gets a value indicating whether the current object being generated is a class.

IsCurrentDelegate

取得值,指出目前產生的物件是否為委派。Gets a value indicating whether the current object being generated is a delegate.

IsCurrentEnum

取得值,指出目前產生的物件是否為列舉型別 (Enumeration)。Gets a value indicating whether the current object being generated is an enumeration.

IsCurrentInterface

取得值,指出目前產生的物件是否為介面。Gets a value indicating whether the current object being generated is an interface.

IsCurrentStruct

取得值,指出目前產生的物件是否為實值型別 (Value Type) 或結構。Gets a value indicating whether the current object being generated is a value type or struct.

NullToken

取得表示 null 的語彙基元 (Token)。Gets the token that represents null.

Options

取得程式碼產生器使用的選項。Gets the options to be used by the code generator.

Output

取得要用於輸出的文字寫入器。Gets the text writer to use for output.

方法

ContinueOnNewLine(String)

產生行接續字元 (Line-Continuation Character),並將指定字串輸出到新行上。Generates a line-continuation character and outputs the specified string on a new line.

CreateEscapedIdentifier(String)

為指定值建立逸出識別項。Creates an escaped identifier for the specified value.

CreateValidIdentifier(String)

為指定值建立有效的識別項。Creates a valid identifier for the specified value.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GenerateArgumentReferenceExpression(CodeArgumentReferenceExpression)

為指定的引數參考運算式產生程式碼。Generates code for the specified argument reference expression.

GenerateArrayCreateExpression(CodeArrayCreateExpression)

為指定的陣列建立運算式產生程式碼。Generates code for the specified array creation expression.

GenerateArrayIndexerExpression(CodeArrayIndexerExpression)

為指定的陣列索引子運算式產生程式碼。Generates code for the specified array indexer expression.

GenerateAssignStatement(CodeAssignStatement)

為指定的指派陳述式 (Assignment Statement) 產生程式碼。Generates code for the specified assignment statement.

GenerateAttachEventStatement(CodeAttachEventStatement)

為指定的附加事件陳述式產生程式碼。Generates code for the specified attach event statement.

GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection)

為指定的屬性區塊結尾產生程式碼。Generates code for the specified attribute block end.

GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection)

為指定的屬性區塊起始產生程式碼。Generates code for the specified attribute block start.

GenerateBaseReferenceExpression(CodeBaseReferenceExpression)

為指定的基底參考運算式產生程式碼。Generates code for the specified base reference expression.

GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression)

為指定的二元運算子運算式產生程式碼。Generates code for the specified binary operator expression.

GenerateCastExpression(CodeCastExpression)

為指定的型別轉換運算式產生程式碼。Generates code for the specified cast expression.

GenerateCodeFromMember(CodeTypeMember, TextWriter, CodeGeneratorOptions)

使用指定的文字寫入器與程式碼產生器選項,產生指定類別成員的程式碼。Generates code for the specified class member using the specified text writer and code generator options.

GenerateComment(CodeComment)

為指定的註解產生程式碼。Generates code for the specified comment.

GenerateCommentStatement(CodeCommentStatement)

為指定的註解陳述式產生程式碼。Generates code for the specified comment statement.

GenerateCommentStatements(CodeCommentStatementCollection)

為指定的註解陳述式產生程式碼。Generates code for the specified comment statements.

GenerateCompileUnit(CodeCompileUnit)

為指定的編譯單位產生程式碼。Generates code for the specified compile unit.

GenerateCompileUnitEnd(CodeCompileUnit)

為編譯單位的結尾產生程式碼。Generates code for the end of a compile unit.

GenerateCompileUnitStart(CodeCompileUnit)

為編譯單位的起始產生程式碼。Generates code for the start of a compile unit.

GenerateConditionStatement(CodeConditionStatement)

為指定的條件陳述式產生程式碼。Generates code for the specified conditional statement.

GenerateConstructor(CodeConstructor, CodeTypeDeclaration)

為指定的建構函式 (Constructor) 產生程式碼。Generates code for the specified constructor.

GenerateDecimalValue(Decimal)

為指定的十進位值產生程式碼。Generates code for the specified decimal value.

GenerateDefaultValueExpression(CodeDefaultValueExpression)

為指定的預設值參考產生程式碼。Generates code for the specified reference to a default value.

GenerateDelegateCreateExpression(CodeDelegateCreateExpression)

為指定的委派建立運算式產生程式碼。Generates code for the specified delegate creation expression.

GenerateDelegateInvokeExpression(CodeDelegateInvokeExpression)

為指定的委派叫用 (Invoke) 運算式產生程式碼。Generates code for the specified delegate invoke expression.

GenerateDirectionExpression(CodeDirectionExpression)

為指定的方向運算式產生程式碼。Generates code for the specified direction expression.

GenerateDirectives(CodeDirectiveCollection)

為指定的程式碼指示詞產生程式碼。Generates code for the specified code directives.

GenerateDoubleValue(Double)

為雙精確度浮點數產生程式碼。Generates code for a double-precision floating point number.

GenerateEntryPointMethod(CodeEntryPointMethod, CodeTypeDeclaration)

為指定的進入點 (Entry Point) 方法產生程式碼。Generates code for the specified entry point method.

GenerateEvent(CodeMemberEvent, CodeTypeDeclaration)

為指定的事件產生程式碼。Generates code for the specified event.

GenerateEventReferenceExpression(CodeEventReferenceExpression)

為指定的事件參考運算式產生程式碼。Generates code for the specified event reference expression.

GenerateExpression(CodeExpression)

為指定的程式碼運算式產生程式碼。Generates code for the specified code expression.

GenerateExpressionStatement(CodeExpressionStatement)

為指定的運算式陳述式產生程式碼。Generates code for the specified expression statement.

GenerateField(CodeMemberField)

為指定的成員欄位產生程式碼。Generates code for the specified member field.

GenerateFieldReferenceExpression(CodeFieldReferenceExpression)

為指定的欄位參考運算式產生程式碼。Generates code for the specified field reference expression.

GenerateGotoStatement(CodeGotoStatement)

為指定的 goto 陳述式產生程式碼。Generates code for the specified goto statement.

GenerateIndexerExpression(CodeIndexerExpression)

為指定的索引子運算式產生程式碼。Generates code for the specified indexer expression.

GenerateIterationStatement(CodeIterationStatement)

為指定的重複陳述式產生程式碼。Generates code for the specified iteration statement.

GenerateLabeledStatement(CodeLabeledStatement)

為指定的標記陳述式 (Labeled Statement) 產生程式碼。Generates code for the specified labeled statement.

GenerateLinePragmaEnd(CodeLinePragma)

為指定的行 Pragma 結尾產生程式碼。Generates code for the specified line pragma end.

GenerateLinePragmaStart(CodeLinePragma)

為指定的行 Pragma 起始產生程式碼。Generates code for the specified line pragma start.

GenerateMethod(CodeMemberMethod, CodeTypeDeclaration)

為指定的方法產生程式碼。Generates code for the specified method.

GenerateMethodInvokeExpression(CodeMethodInvokeExpression)

為指定的方法叫用運算式產生程式碼。Generates code for the specified method invoke expression.

GenerateMethodReferenceExpression(CodeMethodReferenceExpression)

為指定的方法參考運算式產生程式碼。Generates code for the specified method reference expression.

GenerateMethodReturnStatement(CodeMethodReturnStatement)

為指定的方法傳回陳述式產生程式碼。Generates code for the specified method return statement.

GenerateNamespace(CodeNamespace)

為指定的命名空間 (Namespace) 產生程式碼。Generates code for the specified namespace.

GenerateNamespaceEnd(CodeNamespace)

為命名空間的結尾產生程式碼。Generates code for the end of a namespace.

GenerateNamespaceImport(CodeNamespaceImport)

為指定的命名空間匯入產生程式碼。Generates code for the specified namespace import.

GenerateNamespaceImports(CodeNamespace)

為指定的命名空間匯入產生程式碼。Generates code for the specified namespace import.

GenerateNamespaces(CodeCompileUnit)

為指定編譯單位中的命名空間產生程式碼。Generates code for the namespaces in the specified compile unit.

GenerateNamespaceStart(CodeNamespace)

為命名空間的起始產生程式碼。Generates code for the start of a namespace.

GenerateObjectCreateExpression(CodeObjectCreateExpression)

為指定的物件建立運算式產生程式碼。Generates code for the specified object creation expression.

GenerateParameterDeclarationExpression(CodeParameterDeclarationExpression)

為指定的參數宣告運算式產生程式碼。Generates code for the specified parameter declaration expression.

GeneratePrimitiveExpression(CodePrimitiveExpression)

為指定的原始運算式產生程式碼。Generates code for the specified primitive expression.

GenerateProperty(CodeMemberProperty, CodeTypeDeclaration)

為指定的屬性產生程式碼。Generates code for the specified property.

GeneratePropertyReferenceExpression(CodePropertyReferenceExpression)

為指定的屬性參考運算式產生程式碼。Generates code for the specified property reference expression.

GeneratePropertySetValueReferenceExpression(CodePropertySetValueReferenceExpression)

為指定的屬性集 (Property Set) 數值參考運算式產生程式碼。Generates code for the specified property set value reference expression.

GenerateRemoveEventStatement(CodeRemoveEventStatement)

為指定的移除事件陳述式產生程式碼。Generates code for the specified remove event statement.

GenerateSingleFloatValue(Single)

為單精確度浮點數產生程式碼。Generates code for a single-precision floating point number.

GenerateSnippetCompileUnit(CodeSnippetCompileUnit)

輸出指定常值程式碼片段編譯單位的程式碼。Outputs the code of the specified literal code fragment compile unit.

GenerateSnippetExpression(CodeSnippetExpression)

輸出指定常值程式碼片段運算式的程式碼。Outputs the code of the specified literal code fragment expression.

GenerateSnippetMember(CodeSnippetTypeMember)

輸出指定常值程式碼片段類別成員的程式碼。Outputs the code of the specified literal code fragment class member.

GenerateSnippetStatement(CodeSnippetStatement)

輸出指定常值程式碼片段陳述式的程式碼。Outputs the code of the specified literal code fragment statement.

GenerateStatement(CodeStatement)

為指定的陳述式產生程式碼。Generates code for the specified statement.

GenerateStatements(CodeStatementCollection)

為指定的陳述式集合產生程式碼。Generates code for the specified statement collection.

GenerateThisReferenceExpression(CodeThisReferenceExpression)

為指定的 this 參考運算式產生程式碼。Generates code for the specified this reference expression.

GenerateThrowExceptionStatement(CodeThrowExceptionStatement)

為指定的擲回例外狀況 (Exception) 陳述式產生程式碼。Generates code for the specified throw exception statement.

GenerateTryCatchFinallyStatement(CodeTryCatchFinallyStatement)

為指定的 try...catch...finally 陳述式產生程式碼。Generates code for the specified try...catch...finally statement.

GenerateTypeConstructor(CodeTypeConstructor)

為指定的類別建構函式產生程式碼。Generates code for the specified class constructor.

GenerateTypeEnd(CodeTypeDeclaration)

為指定的類別結尾產生程式碼。Generates code for the specified end of the class.

GenerateTypeOfExpression(CodeTypeOfExpression)

為指定的運算式型別產生程式碼。Generates code for the specified type of expression.

GenerateTypeReferenceExpression(CodeTypeReferenceExpression)

為指定的型別參考運算式產生程式碼。Generates code for the specified type reference expression.

GenerateTypes(CodeNamespace)

為指定的命名空間和其所包含的類別產生程式碼。Generates code for the specified namespace and the classes it contains.

GenerateTypeStart(CodeTypeDeclaration)

為指定的類別開頭產生程式碼。Generates code for the specified start of the class.

GenerateVariableDeclarationStatement(CodeVariableDeclarationStatement)

為指定的變數宣告陳述式產生程式碼。Generates code for the specified variable declaration statement.

GenerateVariableReferenceExpression(CodeVariableReferenceExpression)

為指定的變數參考運算式產生程式碼。Generates code for the specified variable reference expression.

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
GetTypeOutput(CodeTypeReference)

取得指定資料型別的名稱。Gets the name of the specified data type.

IsValidIdentifier(String)

取得值,指出指定值是否為有效的識別項。Gets a value indicating whether the specified value is a valid identifier.

IsValidLanguageIndependentIdentifier(String)

取得一個數值,指出指定值是否為有效識別項。Gets a value indicating whether the specified string is a valid identifier.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OutputAttributeArgument(CodeAttributeArgument)

輸出屬性區塊中的引數。Outputs an argument in an attribute block.

OutputAttributeDeclarations(CodeAttributeDeclarationCollection)

為指定的屬性宣告集合產生程式碼。Generates code for the specified attribute declaration collection.

OutputDirection(FieldDirection)

為指定的 FieldDirection 產生程式碼。Generates code for the specified FieldDirection.

OutputExpressionList(CodeExpressionCollection)

為指定的運算式清單產生程式碼。Generates code for the specified expression list.

OutputExpressionList(CodeExpressionCollection, Boolean)

為指定的運算式清單產生程式碼。Generates code for the specified expression list.

OutputFieldScopeModifier(MemberAttributes)

輸出對應於指定屬性的欄位範圍修飾詞 (Modifier)。Outputs a field scope modifier that corresponds to the specified attributes.

OutputIdentifier(String)

輸出指定的識別項。Outputs the specified identifier.

OutputMemberAccessModifier(MemberAttributes)

為指定的成員存取修飾詞產生程式碼。Generates code for the specified member access modifier.

OutputMemberScopeModifier(MemberAttributes)

為指定的成員範圍修飾詞產生程式碼。Generates code for the specified member scope modifier.

OutputOperator(CodeBinaryOperatorType)

為指定的運算子產生程式碼。Generates code for the specified operator.

OutputParameters(CodeParameterDeclarationExpressionCollection)

為指定的參數產生程式碼。Generates code for the specified parameters.

OutputType(CodeTypeReference)

為指定的型別產生程式碼。Generates code for the specified type.

OutputTypeAttributes(TypeAttributes, Boolean, Boolean)

為指定的型別屬性產生程式碼。Generates code for the specified type attributes.

OutputTypeNamePair(CodeTypeReference, String)

為指定的物件型別和名稱配對產生程式碼。Generates code for the specified object type and name pair.

QuoteSnippetString(String)

以逸出程式碼格式化,以轉換指定的字串。Converts the specified string by formatting it with escape codes.

Supports(GeneratorSupport)

取得值,指出是否提供指定程式碼產生支援。Gets a value indicating whether the specified code generation support is provided.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
ValidateIdentifier(String)

如果指定字串不是有效的識別項,即擲回例外狀況。Throws an exception if the specified string is not a valid identifier.

ValidateIdentifiers(CodeObject)

嘗試驗證指定 CodeObjectSystem.CodeDom 樹狀結構中所包含的每個識別項欄位。Attempts to validate each identifier field contained in the specified CodeObject or System.CodeDom tree.

明確介面實作

ICodeGenerator.CreateEscapedIdentifier(String)

為指定值建立逸出識別項。Creates an escaped identifier for the specified value.

ICodeGenerator.CreateValidIdentifier(String)

為指定值建立有效的識別項。Creates a valid identifier for the specified value.

ICodeGenerator.GenerateCodeFromCompileUnit(CodeCompileUnit, TextWriter, CodeGeneratorOptions)

為指定的程式碼文件物件模型 (CodeDOM) 編譯單位產生程式碼,並使用指定的選項將它輸出到指定的文字寫入器。Generates code for the specified Code Document Object Model (CodeDOM) compilation unit and outputs it to the specified text writer using the specified options.

ICodeGenerator.GenerateCodeFromExpression(CodeExpression, TextWriter, CodeGeneratorOptions)

為指定的程式碼文件物件模型 (CodeDOM) 運算式產生程式碼,並將它輸出到指定的文字寫入器。Generates code for the specified Code Document Object Model (CodeDOM) expression and outputs it to the specified text writer.

ICodeGenerator.GenerateCodeFromNamespace(CodeNamespace, TextWriter, CodeGeneratorOptions)

為指定的程式碼文件物件模型 (CodeDOM) 命名空間產生程式碼,並使用指定的選項將它輸出到指定的文字寫入器。Generates code for the specified Code Document Object Model (CodeDOM) namespace and outputs it to the specified text writer using the specified options.

ICodeGenerator.GenerateCodeFromStatement(CodeStatement, TextWriter, CodeGeneratorOptions)

為指定的程式碼文件物件模型 (CodeDOM) 陳述式產生程式碼,並使用指定的選項將它輸出到指定的文字寫入器。Generates code for the specified Code Document Object Model (CodeDOM) statement and outputs it to the specified text writer using the specified options.

ICodeGenerator.GenerateCodeFromType(CodeTypeDeclaration, TextWriter, CodeGeneratorOptions)

為指定的程式碼文件物件模型 (CodeDOM) 型別宣告產生程式碼,並使用指定的選項將它輸出到指定的文字寫入器。Generates code for the specified Code Document Object Model (CodeDOM) type declaration and outputs it to the specified text writer using the specified options.

ICodeGenerator.GetTypeOutput(CodeTypeReference)

取得由指定的 CodeTypeReference 所指示的型別。Gets the type indicated by the specified CodeTypeReference.

ICodeGenerator.IsValidIdentifier(String)

取得指示數值,表示指定的值是否為目前語言的有效識別項。Gets a value that indicates whether the specified value is a valid identifier for the current language.

ICodeGenerator.Supports(GeneratorSupport)

取得值,指出產生器是否支援指定 GeneratorSupport 物件所表示的語言功能。Gets a value indicating whether the generator provides support for the language features represented by the specified GeneratorSupport object.

ICodeGenerator.ValidateIdentifier(String)

如果指定值不是有效的識別項會擲回例外狀況。Throws an exception if the specified value is not a valid identifier.

安全性

LinkDemand
針對立即呼叫者的完全信任的。for full trust for the immediate caller. 此成員無法由部分信任程式碼使用。This class cannot be used by partially trusted code.

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 此類別無法由部分信任程式碼繼承。This class cannot be inherited by partially trusted code.

適用於

另請參閱