From 1a1ddd5601990fc6c5545c1aa5f50baecbe2e8f9 Mon Sep 17 00:00:00 2001 From: Manodasan Wignarajah Date: Sun, 21 Jul 2024 20:09:55 -0700 Subject: [PATCH] Fix IDIC casts throwing exceptions for is operator checks --- src/Tests/FunctionalTests/Collections/Program.cs | 11 ++++++++++- src/WinRT.Runtime/IWinRTObject.net5.cs | 9 +++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Tests/FunctionalTests/Collections/Program.cs b/src/Tests/FunctionalTests/Collections/Program.cs index 50c5121ea..97ed47d3e 100644 --- a/src/Tests/FunctionalTests/Collections/Program.cs +++ b/src/Tests/FunctionalTests/Collections/Program.cs @@ -90,8 +90,17 @@ return 101; } +var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); +var names = profile.GetNetworkNames(); + +List networkNames = new(); +if (names?.Count > 0) +{ + networkNames.AddRange(names); +} + return 100; static bool SequencesEqual(IEnumerable x, params IEnumerable[] list) => list.All((y) => x.SequenceEqual(y)); -static bool AllEqual(T[] x, params T[][] list) => list.All((y) => x.SequenceEqual(y)); +static bool AllEqual(T[] x, params T[][] list) => list.All((y) => x.SequenceEqual(y)); \ No newline at end of file diff --git a/src/WinRT.Runtime/IWinRTObject.net5.cs b/src/WinRT.Runtime/IWinRTObject.net5.cs index c75f85972..ee559c1c2 100644 --- a/src/WinRT.Runtime/IWinRTObject.net5.cs +++ b/src/WinRT.Runtime/IWinRTObject.net5.cs @@ -39,7 +39,8 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT { if (!FeatureSwitches.EnableIDynamicInterfaceCastableSupport) { - throw new NotSupportedException($"Support for 'IDynamicInterfaceCastable' is disabled (make sure that the 'CsWinRTEnableIDynamicInterfaceCastableSupport' property is not set to 'false')."); + return throwIfNotImplemented ? + throw new NotSupportedException($"Support for 'IDynamicInterfaceCastable' is disabled (make sure that the 'CsWinRTEnableIDynamicInterfaceCastableSupport' property is not set to 'false').") : false; } if (QueryInterfaceCache.ContainsKey(interfaceType)) @@ -67,7 +68,7 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT #if NET if (!RuntimeFeature.IsDynamicCodeCompiled) { - throw new NotSupportedException($"IDynamicInterfaceCastable is not supported for generic type '{type}'."); + return throwIfNotImplemented ? throw new NotSupportedException($"IDynamicInterfaceCastable is not supported for generic type '{type}'.") : false; } #endif @@ -103,7 +104,7 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT #if NET if (!RuntimeFeature.IsDynamicCodeCompiled) { - throw new NotSupportedException($"IDynamicInterfaceCastable is not supported for generic type '{type}'."); + return throwIfNotImplemented ? throw new NotSupportedException($"IDynamicInterfaceCastable is not supported for generic type '{type}'.") : false; } #endif @@ -204,7 +205,7 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT #if NET if (!RuntimeFeature.IsDynamicCodeCompiled) { - throw new NotSupportedException($"Cannot construct an object reference for vtable type '{vftblType}'."); + return throwIfNotImplemented ? throw new NotSupportedException($"Cannot construct an object reference for vtable type '{vftblType}'.") : false; } #endif