CodeExpressionStatement 类

定义

表示由单个表达式组成的语句。Represents a statement that consists of a single expression.

public ref class CodeExpressionStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeExpressionStatement : System.CodeDom.CodeStatement
type CodeExpressionStatement = class
    inherit CodeStatement
Public Class CodeExpressionStatement
Inherits CodeStatement
继承
CodeExpressionStatement
属性

示例

下面的示例演示如何CodeExpressionStatement CodeExpression使用对象创建类的实例。The following example demonstrates how to create an instance of the CodeExpressionStatement class by using a CodeExpression object.

// Creates a code expression for a CodeExpressionStatement to contain.
array<CodeExpression^>^ temp = {gcnew CodePrimitiveExpression( "Example string" )};
CodeExpression^ invokeExpression = gcnew CodeMethodInvokeExpression(
   gcnew CodeTypeReferenceExpression( "Console" ),"Write",temp );

// Creates a statement using a code expression.
CodeExpressionStatement^ expressionStatement;
expressionStatement = gcnew CodeExpressionStatement( invokeExpression );

// A C++ code generator produces the following source code for the preceeding example code:

// Console::Write( "Example string" );
// Creates a code expression for a CodeExpressionStatement to contain.
CodeExpression invokeExpression = new CodeMethodInvokeExpression( 
    new CodeTypeReferenceExpression("Console"), 
    "Write", new CodePrimitiveExpression("Example string") );

// Creates a statement using a code expression.
CodeExpressionStatement expressionStatement;
expressionStatement = new CodeExpressionStatement( invokeExpression );                        

// A C# code generator produces the following source code for the preceeding example code:

// Console.Write( "Example string" );
' Creates a code expression for a CodeExpressionStatement to contain.
Dim invokeExpression = New CodeMethodInvokeExpression( _
    New CodeTypeReferenceExpression("Console"), "Write", _
    New CodePrimitiveExpression("Example string"))

' Creates a statement using a code expression.
Dim expressionStatement As CodeExpressionStatement
expressionStatement = New CodeExpressionStatement(invokeExpression)

' A C# code generator produces the following source code for the preceeding example code:
' Console.Write( "Example string" );

注解

包含一个CodeExpression对象,CodeStatementCollection可将其添加到对象中, 从而使某些表达式独立。 CodeExpressionStatementA CodeExpressionStatement contains a CodeExpression object, and it can be added to a CodeStatementCollection object, allowing some expressions to stand alone. 例如, CodeMethodInvokeExpression包含CodeExpressionStatement的可以表示不带返回值的方法调用。For example, a CodeMethodInvokeExpression contained by a CodeExpressionStatement can represent a method call without a return value.

构造函数

CodeExpressionStatement()

初始化 CodeExpressionStatement 类的新实例。Initializes a new instance of the CodeExpressionStatement class.

CodeExpressionStatement(CodeExpression)

使用指定的表达式初始化 CodeExpressionStatement 类的新实例。Initializes a new instance of the CodeExpressionStatement class by using the specified expression.

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives.

(继承自 CodeStatement)
Expression

获取或设置语句的表达式。Gets or sets the expression for the statement.

LinePragma

获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs.

(继承自 CodeStatement)
StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives.

(继承自 CodeStatement)
UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于