官术网_书友最值得收藏!

Platform extensions

As we mentioned previously, UWP supports a wide range of devices. Each of these devices executes its own implementation of .NET Standard and the UWP app model.

Nevertheless, the surface area of this complete API layer might not always apply to the target platform. The UWP app model contains certain APIs that are specific to only a subset of these devices. These types of API modules are in fact left as placeholder methods in the core UWP SDK, while the actual implementation is included in extension modules that can be referenced in your UWP applications:

Without adding the specific SDK, the developers are confined to only universal APIs. Without adding the extension modules, it is highly likely that certain platform-specific methods would throw NotImplementedException or similar, since the actual implementation of these methods only exists in the platform extensions libraries.

After including the target platform extension, the developers are also responsible for executing runtime checks for the methods and events to see whether these APIs are supported in the current device runtime. Developers can make use of various ApiInformation methods, such as IsTypePresent, IsEventPresent, IsMethodPresent, and IsPropertyPresent.

For instance, in order to check whether the current device supports the CameraPressed event (it might be present on a mobile device, though unlikely to be supported on a desktop PC), we would need to resort to IsEventPresent:

 bool isHardwareButtons_CameraPressedAPIPresent = Windows.Foundation.Metadata.ApiInformation.IsEventPresent ("Windows.Phone.UI.Input.HardwareButtons", "CameraPressed");

This runtime check can also be executed at the contract level to see whether a group of events, or other class members that are used to execute a certain action, are supported or not:

 bool isWindows_Devices_Scanners_ScannerDeviceContract_1_0Present = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent ("Windows.Devices.Scanners.ScannerDeviceContract", 1, 0);

This way, developers can avoid situations where the application behavior and compliance with requirements is neither predetermined nor predictable.

主站蜘蛛池模板: 固阳县| 郯城县| 济南市| 敦化市| 枣强县| 郑州市| 绥江县| 南丰县| 栾川县| 蓝山县| 普宁市| 荆门市| 临清市| 高州市| 盐亭县| 河源市| 逊克县| 林西县| 高陵县| 四会市| 梅河口市| 商都县| 霍城县| 佛山市| 文水县| 昭苏县| 甘南县| 太原市| 都江堰市| 来宾市| 资兴市| 鄂托克前旗| 土默特右旗| 苏尼特右旗| 措美县| 漳平市| 富宁县| 洞头县| 姚安县| 绥化市| 开封县|