Check to see if methods can be called from api before calling

I have the following code:

var view = ApplicationView.GetForCurrentView();
var runtimeMethods = view.GetType().GetRuntimeMethods();
if (!view.IsFullScreen)
{
    var tryEnterFullScreenMode = runtimeMethods.FirstOrDefault(
        x => x.Name == "TryEnterFullScreenMode");
    tryEnterFullScreenMode?.Invoke(view, null);
}

What does this mean because my application becomes full-screen, but if I am on a Windows 8.1 pc, I cannot name these methods. How can I first check if this function is available before calling the methods. I will use #if ... # endif? In principle, I would like to use this code only if the application runs on a computer that has access to it (Windows 10 operating system).

+4
source share
2 answers

, -, , /os. , .

1) , . , , , "" API.

2) . 2 . , , , , , , . , . .

, , , : , , , , - . , .

0

Windows 8.1. Windows 10 tryEnterFullScreenMode. Windows 8.1 . , :

var view = ApplicationView.GetForCurrentView();
TypeInfo t = typeof(ApplicationView).GetTypeInfo();
var tryEnterFullScreenMode = t.GetDeclaredMethod("TryEnterFullScreenMode");
if (tryEnterFullScreenMode != null)
{
    tryEnterFullScreenMode.Invoke(view, null);
}

Windows 10 , . , API Windows.Foundation.Metadata.ApiInformation. , , ( ), . , , :

// Useless example since TryEnterFullScreenMode is in the UniversalApiContract
// and so guaranteed to be there in all Windows 10 apps
bool isEnterFullScreenPresent = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "TryEnterFullScreenMode");

if (isEnterFullScreenPresent)
{
    ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
}

API . Windows (UWP) MSDN.

0

Source: https://habr.com/ru/post/1611978/


All Articles