CodeTypeDeclaration.IsPartial 屬性

定義

取得或設定值,指出型別宣告是完整的,還是部分的。

public:
 property bool IsPartial { bool get(); void set(bool value); };
public bool IsPartial { get; set; }
member this.IsPartial : bool with get, set
Public Property IsPartial As Boolean

屬性值

如果類別或結構宣告是實作的部分表示,則為 true,如果宣告是類別或結構的完整實作,則為 false。 預設為 false

範例

此範例示範如何使用 CodeTypeDeclaration 提供跨多個宣告的類別實作。 這個範例會建置初始類別宣告語句,並將 屬性設定 IsPartialtrue

CodeTypeDeclaration^ baseClass = gcnew CodeTypeDeclaration( "DocumentProperties" );
baseClass->IsPartial = true;
baseClass->IsClass = true;
baseClass->Attributes = MemberAttributes::Public;
baseClass->BaseTypes->Add( gcnew CodeTypeReference( System::Object::typeid ) );

// Add the DocumentProperties class to the namespace.
sampleSpace->Types->Add( baseClass );
            CodeTypeDeclaration baseClass = new CodeTypeDeclaration("DocumentProperties");
            baseClass.IsPartial = true;
            baseClass.IsClass = true;
            baseClass.Attributes = MemberAttributes.Public;
            baseClass.BaseTypes.Add(new CodeTypeReference(typeof(System.Object
)));

            // Add the DocumentProperties class to the namespace.
            sampleSpace.Types.Add(baseClass);
Dim baseClass As CodeTypeDeclaration = New CodeTypeDeclaration("DocumentProperties")
baseClass.IsPartial = True
baseClass.IsClass = True
baseClass.Attributes = MemberAttributes.Public
baseClass.BaseTypes.Add(New CodeTypeReference(GetType(System.Object)))

' Add the DocumentProperties class to the namespace.
sampleSpace.Types.Add(baseClass)

範例中的不同方法會擴充 類別實作。 這個方法會建置現有類別的新型別宣告語句,並將 屬性設定 IsPartialtrue。 編譯程式會將兩個部分型別宣告結合在一起,以進行完整的類別實作。

CodeTypeDeclaration^ baseClass = gcnew CodeTypeDeclaration( "DocumentProperties" );
baseClass->IsPartial = true;
baseClass->IsClass = true;
baseClass->Attributes = MemberAttributes::Public;

// Extend the DocumentProperties class in the unit namespace.
( *docPropUnit)->Namespaces[ 0 ]->Types->Add( baseClass );
CodeTypeDeclaration baseClass = new CodeTypeDeclaration("DocumentProperties");
baseClass.IsPartial = true;
baseClass.IsClass = true;
baseClass.Attributes = MemberAttributes.Public;

// Extend the DocumentProperties class in the unit namespace.
docPropUnit.Namespaces[0].Types.Add(baseClass);
Dim baseClass As CodeTypeDeclaration = New CodeTypeDeclaration("DocumentProperties")
baseClass.IsPartial = True
baseClass.IsClass = True
baseClass.Attributes = MemberAttributes.Public

' Extend the DocumentProperties class in the unit namespace.
docPropUnit.Namespaces(0).Types.Add(baseClass)

備註

您可以在一個完整宣告中建置類別或結構實作,或將實作分散到多個宣告。 實作通常會在一個完整型別宣告中提供。 在此情況下,請將類型宣告 IsPartial 屬性設定為 false,表示類型宣告代表類別或結構實作的所有詳細數據。

部分類型宣告可讓您更輕鬆地在應用程式的不同模組中建置類別或結構實作的不同部分。 部分類型宣告可以儲存在一個原始程序檔中,或分散到最終一起編譯的多個原始程序檔,以形成合併的類型實作。

C# 語言透過 關鍵詞支援類別和結構的 partial 部分型別宣告。 Visual Basic 支援具有 關鍵詞之類別和結構的 Partial 部分類型宣告。 並非所有程式代碼產生器都支援部分類型宣告,因此您應該使用旗標PartialTypes呼叫 Supports 方法來測試此支援。

注意

類別和結構支援部分類型宣告。 如果您為列舉或介面指定部分類型宣告,產生的程式代碼會產生編譯程序錯誤。

在多個宣告之間提供類別或結構實作時,請將 IsPartial 初始宣告和所有補充宣告的 屬性 true 設定為 。 初始宣告必須完整指定型別簽章,包括存取修飾詞、繼承的類型,以及實作的介面。 補充宣告不需要重新指定類型簽章。 如果您重新定義增補宣告中的類型簽章,通常會產生編譯程序錯誤。

Visual Studio 2005 使用部分類型來分隔用戶產生的程式代碼與設計工具程序代碼。 在 Visual Basic Windows 應用程式專案中,用戶程式代碼會放在未由 Partial 關鍵詞限定的部分類別中;設計工具提供的程式代碼會出現在具有 Partial 關鍵詞的部分類別中。 在 C# 中,使用者程式代碼和設計工具程式代碼都會出現在 關鍵詞所識別的部分類別中 partial

適用於

另請參閱