Modifier

Partager via


CodeTypeDeclaration.IsPartial Property

Definition

Gets or sets a value indicating whether the type declaration is complete or partial.

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

Property Value

true if the class or structure declaration is a partial representation of the implementation; false if the declaration is a complete implementation of the class or structure. The default is false.

Examples

This example demonstrates using a CodeTypeDeclaration to supply a class implementation across multiple declarations. The example builds the initial class declaration statement and sets the IsPartial property to true.

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)

A different method in the example extends the class implementation. This method builds a new type declaration statement for the existing class and sets the IsPartial property to true. The compiler combines the two partial type declarations together for the complete class implementation.

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)

Remarks

You can build a class or structure implementation in one complete declaration, or spread the implementation across multiple declarations. Implementations are commonly supplied in one complete type declaration. In this case, set the type declaration IsPartial property to false, which indicates that the type declaration represents all details for the class or structure implementation.

A partial type declaration makes it easier to build different portions of a class or structure implementation in different modules of your application. The partial type declarations can be stored in one source file, or spread across multiple source files that are eventually compiled together to form the combined type implementation.

The C# language supports partial type declarations of classes and structures through the partial keyword. Visual Basic supports partial type declarations of classes and structures with the Partial keyword. Not all code generators support partial type declarations, so you should test for this support by calling the Supports method with the flag PartialTypes.

Note

Partial type declarations are supported for classes and structures. If you specify a partial type declaration for an enumeration or interface, the generated code produces compiler errors.

When supplying a class or structure implementation across multiple declarations, set the IsPartial property to true for the initial declaration and all supplemental declarations. The initial declaration must fully specify the type signature, including access modifiers, inherited types, and implemented interfaces. The supplementary declarations do not need to re-specify the type signature. A compiler error typically results if you redefine the type signature in a supplementary declaration.

Visual Studio 2005 uses partial types to separate user-generated code from designer code. In Visual Basic Windows Application projects, the user code is placed in a partial class that is not qualified by the Partial keyword; the designer-provided code appears in the partial class that has the Partial keyword. In C#, both the user code and designer code appear in partial classes identified by the partial keyword.

Applies to

See also