Deprecating types and members (C++/CX)

In C++/CX, deprecation of Windows Runtime types and members for producers and consumers by using the Deprecated attribute is supported. If you consume an API to which this attribute has been applied, you get a compile-time warning message that indicates that the API is deprecated and also recommends an alternative API to use. In your own public types and methods, you can apply this attribute and supply your own custom message.

Caution

The Deprecated attribute is for use only with Windows Runtime types. For standard C++ classes and members, use __declspec(deprecated).

Example

The following example shows how to deprecate your own public APIs—for example, in a Windows Runtime component. The second parameter, of type Windows:Foundation::Metadata::DeprecationType specifies whether the API is being deprecated or removed. Currently only the DeprecationType::Deprecated value is supported. The third parameter in the attribute specifies the Windows::Foundation::Metadata::Platform to which the attribute applies.


namespace wfm = Windows::Foundation::Metadata;  

public ref class Bicycle sealed  
{  

public:  
    property double Speed;  

    [wfm::Deprecated("Use the Speed property to compute the angular speed of the wheel", wfm::DeprecationType::Deprecate, 0x0)]  
    double ComputeAngularVelocity();  
};  

Supported targets

The following table lists the constructs to which the Deprecated attribute may be applied:

||
|-|
|XAML control|
|delegate|
|event|
|enum field|
|enum|
|struct|
|method|
|class|
|interface|
|property|
|struct field|
|parameterized constructor|

See Also

Type System
Visual C++ Language Reference
Namespaces Reference