CodeMemberMethod 類別

定義

表示型別方法的宣告。Represents a declaration for a method of a type.

public ref class CodeMemberMethod : System::CodeDom::CodeTypeMember
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeMemberMethod : System.CodeDom.CodeTypeMember
type CodeMemberMethod = class
    inherit CodeTypeMember
Public Class CodeMemberMethod
Inherits CodeTypeMember
繼承
CodeMemberMethod
衍生
屬性

範例

下列範例示範CodeMemberMethod如何使用來宣告可接受參數並傳回值的方法。The following example demonstrates use of a CodeMemberMethod to declare a method that accepts a parameter and returns a value.

// Defines a method that returns a string passed to it.
CodeMemberMethod^ method1 = gcnew CodeMemberMethod;
method1->Name = "ReturnString";
method1->ReturnType = gcnew CodeTypeReference( "System.String" );
method1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.String","text" ) );
method1->Statements->Add( gcnew CodeMethodReturnStatement( gcnew CodeArgumentReferenceExpression( "text" ) ) );

// A C# code generator produces the following source code for the preceeding example code:
//    private string ReturnString(string text) 
//    {
//        return text;
//    }
// Defines a method that returns a string passed to it.
CodeMemberMethod method1 = new CodeMemberMethod();            
method1.Name = "ReturnString";
method1.ReturnType = new CodeTypeReference("System.String");
method1.Parameters.Add( new CodeParameterDeclarationExpression("System.String", "text") );
method1.Statements.Add( new CodeMethodReturnStatement( new CodeArgumentReferenceExpression("text") ) );            

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

//    private string ReturnString(string text) 
//    {
//        return text;
//    }
' Defines a method that returns a string passed to it.
Dim method1 As New CodeMemberMethod()
method1.Name = "ReturnString"
method1.ReturnType = New CodeTypeReference("System.String")
method1.Parameters.Add(New CodeParameterDeclarationExpression("System.String", "text"))
method1.Statements.Add(New CodeMethodReturnStatement(New CodeArgumentReferenceExpression("text")))

' A Visual Basic code generator produces the following source code for the preceeding example code:

'   Private Function ReturnString(ByVal [text] As String) As String
'       Return [Text]
'   End Function

備註

CodeMemberMethod可以用來代表方法的宣告。CodeMemberMethod can be used to represent the declaration for a method.

ReturnType屬性會指定方法的傳回值的資料類型。The ReturnType property specifies the data type of the method's return value. Parameters屬性包含方法的參數。The Parameters property contains the method's parameters. Statements屬性包含方法的語句。The Statements property contains the statements of the method.

建構函式

CodeMemberMethod()

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

屬性

Attributes

取得或設定成員的屬性 (Attribute)。Gets or sets the attributes of the member.

(繼承來源 CodeTypeMember)
Comments

取得型別成員的註解集合。Gets the collection of comments for the type member.

(繼承來源 CodeTypeMember)
CustomAttributes

取得或設定成員的自訂屬性。Gets or sets the custom attributes of the member.

(繼承來源 CodeTypeMember)
EndDirectives

取得成員的結尾指示詞。Gets the end directives for the member.

(繼承來源 CodeTypeMember)
ImplementationTypes

取得這個方法所實作的介面的資料型別,除非它是 PrivateImplementationType 屬性所指示的私用 (Private) 方法實作。Gets the data types of the interfaces implemented by this method, unless it is a private method implementation, which is indicated by the PrivateImplementationType property.

LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。Gets or sets the line on which the type member statement occurs.

(繼承來源 CodeTypeMember)
Name

取得或設定成員的名稱。Gets or sets the name of the member.

(繼承來源 CodeTypeMember)
Parameters

取得方法的參數宣告。Gets the parameter declarations for the method.

PrivateImplementationType

取得或設定這個方法之介面的資料型別 (如果是私用),實作其方法 (如果有的話)。Gets or sets the data type of the interface this method, if private, implements a method of, if any.

ReturnType

取得或設定方法之傳回值的資料型別。Gets or sets the data type of the return value of the method.

ReturnTypeCustomAttributes

取得方法之傳回型別的自訂屬性 (Attribute)。Gets the custom attributes of the return type of the method.

StartDirectives

取得成員的開頭指示詞。Gets the start directives for the member.

(繼承來源 CodeTypeMember)
Statements

取得方法中的陳述式 (Statement)。Gets the statements within the method.

TypeParameters

取得目前泛型方法的型別參數。Gets the type parameters for the current generic method.

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 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

事件

PopulateImplementationTypes

第一次存取 ImplementationTypes 集合時,將引發的事件。An event that will be raised the first time the ImplementationTypes collection is accessed.

PopulateParameters

第一次存取 Parameters 集合時,將引發的事件。An event that will be raised the first time the Parameters collection is accessed.

PopulateStatements

第一次存取 Statements 集合時,將引發的事件。An event that will be raised the first time the Statements collection is accessed.

適用於