CodeTypeConstructor 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表類別的靜態建構子。
public ref class CodeTypeConstructor : System::CodeDom::CodeMemberMethod
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeTypeConstructor : System.CodeDom.CodeMemberMethod
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeTypeConstructor = class
inherit CodeMemberMethod
Public Class CodeTypeConstructor
Inherits CodeMemberMethod
- 繼承
- 屬性
範例
以下範例示範如何使用 a CodeTypeConstructor 來宣告一個型別的靜態建構子。
// Declares a new type for a static constructor.
CodeTypeDeclaration type1 = new CodeTypeDeclaration("Type1");
// Declares a static constructor.
CodeTypeConstructor constructor2 = new CodeTypeConstructor();
// Adds the static constructor to the type.
type1.Members.Add( constructor2 );
// A C# code generator produces the following source code for the preceeding example code:
// public class Type1
// {
//
// static Type1()
// {
// }
// }
' Declares a new type for a static constructor.
Dim type1 As New CodeTypeDeclaration("Type1")
' Declares a static constructor.
Dim constructor2 As New CodeTypeConstructor()
' Adds the static constructor to the type.
type1.Members.Add(constructor2)
' A Visual Basic code generator produces the following source code for the preceeding example code:
' Public Class Type1
'
' Shared Sub New()
' End Sub
' End Class
備註
CodeTypeConstructor 可以用來表示類別的靜態建構子。 當型別載入時,靜態建構子會被呼叫一次。
Note
並非所有語言都支援靜態建構子。 可透過呼叫 Supports 該 StaticConstructors 標誌來檢查靜態建構子的支援,以判斷特定語言的程式碼產生器是否支援靜態建構子。
建構函式
| 名稱 | Description |
|---|---|
| CodeTypeConstructor() |
初始化 CodeTypeConstructor 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Attributes |
取得或設定成員的屬性。 (繼承來源 CodeTypeMember) |
| Comments |
取得該類型成員的評論集合。 (繼承來源 CodeTypeMember) |
| CustomAttributes |
取得或設定成員的自訂屬性。 (繼承來源 CodeTypeMember) |
| EndDirectives |
負責成員的最終指令。 (繼承來源 CodeTypeMember) |
| ImplementationTypes |
取得此方法實作的介面資料型態,除非是私有方法實作,該特性可表示 PrivateImplementationType 。 (繼承來源 CodeMemberMethod) |
| LinePragma |
取得或設定型別成員陳述句所處的行。 (繼承來源 CodeTypeMember) |
| Name |
取得或設定成員的名字。 (繼承來源 CodeTypeMember) |
| Parameters |
取得方法的參數宣告。 (繼承來源 CodeMemberMethod) |
| PrivateImplementationType |
取得或設定介面的資料型態,此方法若為私有,則實作一個方法(若有)。 (繼承來源 CodeMemberMethod) |
| ReturnType |
取得或設定方法回傳值的資料型別。 (繼承來源 CodeMemberMethod) |
| ReturnTypeCustomAttributes |
取得方法回傳類型的自訂屬性。 (繼承來源 CodeMemberMethod) |
| StartDirectives |
為成員取得啟動指令。 (繼承來源 CodeTypeMember) |
| Statements |
取得方法中的語句。 (繼承來源 CodeMemberMethod) |
| TypeParameters |
取得目前泛型方法的類型參數。 (繼承來源 CodeMemberMethod) |
| UserData |
取得目前物件的使用者可定義資料。 (繼承來源 CodeObject) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
事件
| 名稱 | Description |
|---|---|
| PopulateImplementationTypes |
這個事件會在首次 ImplementationTypes 存取收藏時被提出。 (繼承來源 CodeMemberMethod) |
| PopulateParameters |
這個事件會在首次 Parameters 存取收藏時被提出。 (繼承來源 CodeMemberMethod) |
| PopulateStatements |
這個事件會在首次 Statements 存取收藏時被提出。 (繼承來源 CodeMemberMethod) |