Skip to content

Commit

Permalink
Implement fallbacks for empty, null, or nonexistent in managed runtim…
Browse files Browse the repository at this point in the history
…e class names. (#218)
  • Loading branch information
jkoritzinsky authored Apr 24, 2020
1 parent 230b31b commit f9313a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion WinRT.Runtime/ComWrappersSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ private static Func<IInspectable, object> CreateArrayFactory(Type implementation

internal static Func<IInspectable, object> CreateTypedRcwFactory(string runtimeClassName)
{
// If we don't have a runtime class name, then we just use IInspectable.
if (string.IsNullOrEmpty(runtimeClassName))
{
return (IInspectable obj) => obj;
}
// PropertySet and ValueSet can return IReference<String> but Nullable<String> is illegal
if (runtimeClassName == "Windows.Foundation.IReference`1<String>")
{
Expand All @@ -277,7 +282,18 @@ internal static Func<IInspectable, object> CreateTypedRcwFactory(string runtimeC
return (IInspectable obj) => new ABI.System.Nullable<Type>(obj.ObjRef);
}

var (implementationType, _) = TypeNameSupport.FindTypeByName(runtimeClassName.AsSpan());
Type implementationType = null;

try
{
(implementationType, _) = TypeNameSupport.FindTypeByName(runtimeClassName.AsSpan());
}
catch (TypeLoadException)
{
// If we reach here, then we couldn't find a type that matches the runtime class name.
// Fall back to using IInspectable directly.
return (IInspectable obj) => obj;
}

if (implementationType.IsGenericType && implementationType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair<,>))
{
Expand Down
1 change: 1 addition & 0 deletions WinUI/WinUIDesktopSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public App()
Window myWindow;
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var value = DependencyProperty.UnsetValue;
var button = new Button
{
Content = "Click me to load MainPage",
Expand Down

0 comments on commit f9313a9

Please sign in to comment.