/// <summary> /// Converts the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="targetType">Type of the target.</param> /// <param name="parameter">The parameter.</param> /// <returns>System.Object.</returns> protected override object Convert(object value, System.Type targetType, object parameter) { var parameterAsString = ObjectToStringHelper.ToString(parameter); var isSupported = false; var supportedPlatforms = parameterAsString.Split(new[] { '|' }); foreach (var supportedPlatform in supportedPlatforms) { KnownPlatforms platform = KnownPlatforms.Unknown; if (Enum <KnownPlatforms> .TryParse(supportedPlatform, out platform)) { if (Platforms.IsPlatformSupported(platform)) { isSupported = true; break; } } } if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter)) { isSupported = !isSupported; } return(isSupported); }
/// <summary> /// Determines whether the specified known platforms is currently supported. /// </summary> /// <param name="platformToCheck">The platform to check.</param> /// <param name="currentPlatform">The current platform.</param> /// <returns><c>true</c> if the platform is supported; otherwise, <c>false</c>.</returns> public static bool IsPlatformSupported(KnownPlatforms platformToCheck, SupportedPlatforms currentPlatform) { switch (platformToCheck) { case KnownPlatforms.Unknown: return(false); case KnownPlatforms.NET: return(currentPlatform == SupportedPlatforms.NET45 || currentPlatform == SupportedPlatforms.NET46 || currentPlatform == SupportedPlatforms.NET47 || currentPlatform == SupportedPlatforms.NET50); case KnownPlatforms.NET45: return(currentPlatform == SupportedPlatforms.NET45); case KnownPlatforms.NET46: return(currentPlatform == SupportedPlatforms.NET46); case KnownPlatforms.NET47: return(currentPlatform == SupportedPlatforms.NET47); case KnownPlatforms.NET50: return(currentPlatform == SupportedPlatforms.NET50); case KnownPlatforms.NetStandard: return(currentPlatform == SupportedPlatforms.NetStandard20); case KnownPlatforms.NetStandard20: return(currentPlatform == SupportedPlatforms.NetStandard20); case KnownPlatforms.WindowsUniversal: return(currentPlatform == SupportedPlatforms.WindowsUniversal); case KnownPlatforms.Xamarin: return(currentPlatform == SupportedPlatforms.Android || currentPlatform == SupportedPlatforms.iOS); case KnownPlatforms.XamarinAndroid: return(currentPlatform == SupportedPlatforms.Android); case KnownPlatforms.XamariniOS: return(currentPlatform == SupportedPlatforms.iOS); case KnownPlatforms.XamarinForms: return(currentPlatform == SupportedPlatforms.PCL); case KnownPlatforms.PCL: return(currentPlatform == SupportedPlatforms.PCL); default: throw new ArgumentOutOfRangeException("platformToCheck"); } }
/// <summary> /// Converts the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="targetType">Type of the target.</param> /// <param name="parameter">The parameter.</param> /// <returns>System.Object.</returns> protected override object Convert(object value, System.Type targetType, object parameter) { var parameterAsString = ObjectToStringHelper.ToString(parameter); var supportedPlatforms = parameterAsString.Split(new[] { '|' }); foreach (var supportedPlatform in supportedPlatforms) { KnownPlatforms platform = KnownPlatforms.Unknown; if (Enum <KnownPlatforms> .TryParse(supportedPlatform, out platform)) { if (Platforms.IsPlatformSupported(platform)) { return(true); } } } return(false); }
/// <summary> /// Determines whether the specified known platforms is currently supported. /// </summary> /// <param name="platformToCheck">The platform to check.</param> /// <returns><c>true</c> if the platform is supported; otherwise, <c>false</c>.</returns> public static bool IsPlatformSupported(KnownPlatforms platformToCheck) { return(IsPlatformSupported(platformToCheck, CurrentPlatform)); }
/// <summary> /// Determines whether the specified known platforms is currently supported. /// </summary> /// <param name="platformToCheck">The platform to check.</param> /// <param name="currentPlatform">The current platform.</param> /// <returns><c>true</c> if the platform is supported; otherwise, <c>false</c>.</returns> public static bool IsPlatformSupported(KnownPlatforms platformToCheck, SupportedPlatforms currentPlatform) { switch (platformToCheck) { case KnownPlatforms.Unknown: return(false); case KnownPlatforms.NET: return(currentPlatform == SupportedPlatforms.NET40 || currentPlatform == SupportedPlatforms.NET45 || currentPlatform == SupportedPlatforms.NET46 || currentPlatform == SupportedPlatforms.NET50); case KnownPlatforms.NET40: return(currentPlatform == SupportedPlatforms.NET40); case KnownPlatforms.NET45: return(currentPlatform == SupportedPlatforms.NET45); case KnownPlatforms.NET46: return(currentPlatform == SupportedPlatforms.NET46); case KnownPlatforms.NET50: return(currentPlatform == SupportedPlatforms.NET50); case KnownPlatforms.Silverlight: return(currentPlatform == SupportedPlatforms.Silverlight5); case KnownPlatforms.Silverlight5: return(currentPlatform == SupportedPlatforms.Silverlight5); case KnownPlatforms.WindowsPhone: return(currentPlatform == SupportedPlatforms.WindowsPhone80 || currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight || currentPlatform == SupportedPlatforms.WindowsPhone81Runtime); case KnownPlatforms.WindowsPhoneSilverlight: return(currentPlatform == SupportedPlatforms.WindowsPhone80 || currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight); case KnownPlatforms.WindowsPhoneRuntime: return(currentPlatform == SupportedPlatforms.WindowsPhone81Runtime); case KnownPlatforms.WindowsPhone80: return(currentPlatform == SupportedPlatforms.WindowsPhone80); case KnownPlatforms.WindowsPhone81Silverlight: return(currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight); case KnownPlatforms.WindowsPhone81Runtime: return(currentPlatform == SupportedPlatforms.WindowsPhone81Runtime); case KnownPlatforms.WindowsRuntime: return(currentPlatform == SupportedPlatforms.WindowsRuntime80 || currentPlatform == SupportedPlatforms.WindowsRuntime81); case KnownPlatforms.WindowsRuntime80: return(currentPlatform == SupportedPlatforms.WindowsRuntime80); case KnownPlatforms.WindowsRuntime81: return(currentPlatform == SupportedPlatforms.WindowsRuntime81); case KnownPlatforms.WindowsUniversal: return(currentPlatform == SupportedPlatforms.WindowsUniversal100); case KnownPlatforms.WindowsUniversal100: return(currentPlatform == SupportedPlatforms.WindowsUniversal100); case KnownPlatforms.Xamarin: return(currentPlatform == SupportedPlatforms.Android || currentPlatform == SupportedPlatforms.iOS); case KnownPlatforms.XamarinAndroid: return(currentPlatform == SupportedPlatforms.Android); case KnownPlatforms.XamariniOS: return(currentPlatform == SupportedPlatforms.iOS); case KnownPlatforms.XamarinForms: return(currentPlatform == SupportedPlatforms.PCL); case KnownPlatforms.PCL: return(currentPlatform == SupportedPlatforms.PCL); default: throw new ArgumentOutOfRangeException("platformToCheck"); } }
public void ReturnsFalseForUnsupportedPlatform(KnownPlatforms platformToCheck, SupportedPlatforms currentPlatform) { Assert.IsFalse(Platforms.IsPlatformSupported(platformToCheck, currentPlatform)); }
/// <summary> /// Determines whether the specified known platforms is currently supported. /// </summary> /// <param name="platformToCheck">The platform to check.</param> /// <param name="currentPlatform">The current platform.</param> /// <returns><c>true</c> if the platform is supported; otherwise, <c>false</c>.</returns> public static bool IsPlatformSupported(KnownPlatforms platformToCheck, SupportedPlatforms currentPlatform) { switch (platformToCheck) { case KnownPlatforms.Unknown: return false; case KnownPlatforms.NET: return currentPlatform == SupportedPlatforms.NET40 || currentPlatform == SupportedPlatforms.NET45 || currentPlatform == SupportedPlatforms.NET46 || currentPlatform == SupportedPlatforms.NET50; case KnownPlatforms.NET40: return currentPlatform == SupportedPlatforms.NET40; case KnownPlatforms.NET45: return currentPlatform == SupportedPlatforms.NET45; case KnownPlatforms.NET46: return currentPlatform == SupportedPlatforms.NET46; case KnownPlatforms.NET50: return currentPlatform == SupportedPlatforms.NET50; case KnownPlatforms.Silverlight: return currentPlatform == SupportedPlatforms.Silverlight5; case KnownPlatforms.Silverlight5: return currentPlatform == SupportedPlatforms.Silverlight5; case KnownPlatforms.WindowsPhone: return currentPlatform == SupportedPlatforms.WindowsPhone80 || currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight || currentPlatform == SupportedPlatforms.WindowsPhone81Runtime; case KnownPlatforms.WindowsPhoneSilverlight: return currentPlatform == SupportedPlatforms.WindowsPhone80 || currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight; case KnownPlatforms.WindowsPhoneRuntime: return currentPlatform == SupportedPlatforms.WindowsPhone81Runtime; case KnownPlatforms.WindowsPhone80: return currentPlatform == SupportedPlatforms.WindowsPhone80; case KnownPlatforms.WindowsPhone81Silverlight: return currentPlatform == SupportedPlatforms.WindowsPhone81Silverlight; case KnownPlatforms.WindowsPhone81Runtime: return currentPlatform == SupportedPlatforms.WindowsPhone81Runtime; case KnownPlatforms.WindowsRuntime: return currentPlatform == SupportedPlatforms.WindowsRuntime80 || currentPlatform == SupportedPlatforms.WindowsRuntime81; case KnownPlatforms.WindowsRuntime80: return currentPlatform == SupportedPlatforms.WindowsRuntime80; case KnownPlatforms.WindowsRuntime81: return currentPlatform == SupportedPlatforms.WindowsRuntime81; case KnownPlatforms.WindowsUniversal: return currentPlatform == SupportedPlatforms.WindowsUniversal100; case KnownPlatforms.WindowsUniversal100: return currentPlatform == SupportedPlatforms.WindowsUniversal100; case KnownPlatforms.Xamarin: return currentPlatform == SupportedPlatforms.Android || currentPlatform == SupportedPlatforms.iOS; case KnownPlatforms.XamarinAndroid: return currentPlatform == SupportedPlatforms.Android; case KnownPlatforms.XamariniOS: return currentPlatform == SupportedPlatforms.iOS; case KnownPlatforms.PCL: return currentPlatform == SupportedPlatforms.PCL; default: throw new ArgumentOutOfRangeException("platformToCheck"); } }
/// <summary> /// Determines whether the specified known platforms is currently supported. /// </summary> /// <param name="platformToCheck">The platform to check.</param> /// <returns><c>true</c> if the platform is supported; otherwise, <c>false</c>.</returns> public static bool IsPlatformSupported(KnownPlatforms platformToCheck) { return IsPlatformSupported(platformToCheck, CurrentPlatform); }