Skip to content

Commit

Permalink
fixed regression in casting composable types (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottj1s authored Oct 14, 2020
1 parent 382e321 commit 27073d6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion WinRT.Runtime/CastExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ private static IObjectReference GetRefForObject(object value)
}

private static bool TryGetComposedRefForQI(object value, out IObjectReference objRef)
{
{
#if NETSTANDARD2_0
var getReferenceMethod = value.GetType().GetMethod("GetDefaultReference", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(typeof(IUnknownVftbl));
if (getReferenceMethod is null)
{
Expand All @@ -111,6 +112,15 @@ private static bool TryGetComposedRefForQI(object value, out IObjectReference ob
}
objRef = (IObjectReference)getReferenceMethod.Invoke(value, Array.Empty<object>());
return true;
#else
if(value is IWinRTObject winrtObj)
{
objRef = winrtObj.NativeObject;
return true;
}
objRef = null;
return false;
#endif
}
}
}

0 comments on commit 27073d6

Please sign in to comment.