Partial Types

Storing source text for a type in a single file is a good developer practice, however, often a type declaration is so large that this constraint seems to be impractical. Partial types enable the user to split declarations of classes or structures, or interfaces into two or more source files. Also, partial types enable the user to separate machine generated code from manually written code so that it is easier to augment code generated by a tool.

To define partial types, use the Partial modifier in the type declaration. Every declaration part must contain this modifier and be declared within the same namespace as the other parts are. The Partial modifier indicates that a type can be declared elsewhere but the existence of such overriding is optional. It is possible to have a type declaration consisting of a single part that contains the Partial modifier.

Partial-type attributes are determined by combining attributes specified for each of the parts in random order.

If a partial class inherits from a parent class, all the other parts must also inherit from this parent class.

//First part of class
Partial Abstract Class PartClass
    
Abstract Public Sub Test();
    
Abstract Public Sub Test1();
End Class;
//Second part of class
Partial Abstract Class PartClass
    
Abstract Public Sub Test2();
    
Abstract Public Sub Test3();
End Class;
//Implementation
Class TestClass: PartClass
    
Public Override Sub Test();
    
Begin
    
End Sub;

    
Public Override Sub Test1();
    
Begin
    
End Sub;

    
Public Override Sub Test2();
    
Begin
    
End Sub;

    
Public Override Sub Test3();
    
Begin
    
End Sub;
End Class;

//First part of completed class
Final Partial Class FinalPartClass
    
Sub Test4();
    
Begin
    
End Sub;
End Class;
//Second part of completed class
Final Partial Class FinalPartClass
    
Sub Test5();
    
Begin
    
End Sub;
End Class;

//First part of interface
Partial Interface IPartInterface
    
Sub Test();
    
Sub Test1();
End Interface;
//Second part of interface
Partial Interface IPartInterface
    
Sub Test2();
    
Sub Test3();
End Interface;
//Implementation of interface in partial classes
Partial Class PartClass1: IPartInterface
    
Public Sub Test();
    
Begin
    
End Sub;

    
Public Sub Test3();
    
Begin
    
End Sub;
End Class;
Partial Class PartClass1: IPartInterface
    
Public Sub Test1();
    
Begin
    
End Sub;

    
Public Sub Test2();
    
Begin
    
End Sub;
End Class;

//Part of structure with constants
Partial Struct ObjectModel
    
Public Const Width = 1000;
    
Public Const Height = 500;
End Struct;
//Part of structure with variables
Partial Struct ObjectModel
    
Public SizeInMemory: Double;
End Struct;
//Part of structure with main implementation
Partial Struct ObjectModel
    _a: double;
    _b: double;
    _meth: string;
    _res: object;
    
Public Constructor ObjectModel(a: double; b: double);
    
Begin
        _a := a;
        _b := b;
    
End Constructor;

    
Public Property Method: String
        
Get
        
Begin
            
Return _meth
        
End Get
        
Set
        
Begin
            _meth := Value;
        
End Set
    
End Property;

    
Public Property Result: object
        
Get
        
Begin
            
Return _res
        
End Get
    
End Property Result;

    
Public Sub Calculate();
    
Begin
        
//...
        //Some calculations with calculation of variables SizeInMemory and _res
        //...
    End Sub;
End Struct;

See also:

Fore.NET Language Guide