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

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.

主站蜘蛛池模板: 蛟河市| 岳阳市| 长武县| 和政县| 开封县| 宜良县| 寿阳县| 阳朔县| 梓潼县| 云南省| 临漳县| 灌南县| 湛江市| 兴海县| 墨玉县| 军事| 特克斯县| 通化县| 三河市| 武清区| 广灵县| 苏尼特左旗| 高密市| 舟曲县| 茶陵县| 嘉祥县| 宁海县| 鞍山市| 三穗县| 临朐县| 靖远县| 堆龙德庆县| 阳江市| 增城市| 定兴县| 汝南县| 吉木萨尔县| 宝应县| 彰化县| 安图县| 铅山县|