Partial classes (Visual C++ for Windows Runtime)

Expand
2 out of 2 rated this helpful - Rate this topic

Partial classes (Visual C++ for Windows Runtime)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

A partial class is a construct that supports scenarios in which you are editing one portion of a class definition and automatic code-generating software, such as the XAML designer, is also editing code in the same class. One part of a class is defined in a code file that only the designer writes to. The other part of the class is defined in a file that only you edit. Partial classes help prevent your code from being overwritten by the designer.

The following example shows the Address class defined across two code files. The designer modifies Address.details.h and you edit Address.h. Note that only the class definition in the first file uses the partial keyword.

// Address.details.h
partial ref class Address
{
private:
  Platform::String^ street_;
  Platform::String^ city_;
  Platform::String^ state_;
  Platform::String^ zip_;
  Platform::String^ country_;
  void ValidateAddress(bool normalize = true);
};
// Address.h
#include "Address.details.h"
ref class Address
{
public:
  Address(Platform::String^ street, Platform::String^ city, Platform::String^ state,
    Platform::String^ zip, Platform::String^ country);
  property Platform::String^ Street { Platform::String^ get(); }
  property Platform::String^ City { Platform::String^ get(); }
  property Platform::String^ State { Platform::String^ get(); }
  property Platform::String^ Zip { Platform::String^ get(); }
  property Platform::String^ Country { Platform::String^ get(); }
};

Did you find this helpful?
(1500 characters remaining)