CodeMemberMethod 類別

定義

表示型別方法的宣告。

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

範例

下列範例示範如何使用 CodeMemberMethod 宣告接受參數並傳回值的方法。

// 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 可以用來表示方法的宣告。

屬性 ReturnType 會指定方法傳回值的數據類型。 屬性 Parameters 包含方法的參數。 屬性 Statements 包含 方法的語句。

建構函式

CodeMemberMethod()

初始化 CodeMemberMethod 類別的新執行個體。

屬性

Attributes

取得或設定成員的屬性 (Attribute)。

(繼承來源 CodeTypeMember)
Comments

取得型別成員的註解集合。

(繼承來源 CodeTypeMember)
CustomAttributes

取得或設定成員的自訂屬性。

(繼承來源 CodeTypeMember)
EndDirectives

取得成員的結尾指示詞。

(繼承來源 CodeTypeMember)
ImplementationTypes

取得這個方法所實作的介面的資料型別,除非它是 PrivateImplementationType 屬性所指示的私用 (Private) 方法實作。

LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。

(繼承來源 CodeTypeMember)
Name

取得或設定成員的名稱。

(繼承來源 CodeTypeMember)
Parameters

取得方法的參數宣告。

PrivateImplementationType

取得或設定這個方法之介面的資料型別 (如果是私用),實作其方法 (如果有的話)。

ReturnType

取得或設定方法之傳回值的資料型別。

ReturnTypeCustomAttributes

取得方法之傳回型別的自訂屬性 (Attribute)。

StartDirectives

取得成員的開頭指示詞。

(繼承來源 CodeTypeMember)
Statements

取得方法中的陳述式 (Statement)。

TypeParameters

取得目前泛型方法的型別參數。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

PopulateImplementationTypes

第一次存取 ImplementationTypes 集合時,將引發的事件。

PopulateParameters

第一次存取 Parameters 集合時,將引發的事件。

PopulateStatements

第一次存取 Statements 集合時,將引發的事件。

適用於