Skip to content

Commit

Permalink
Add the ObjectReferenceWrapper attribute to enable unwrapping WinRT.I…
Browse files Browse the repository at this point in the history
…Inspectable instances. (#273)

* Add the ObjectReferenceWrapper attribute to enable unwrapping WinRT.IInspectable instances.

* Add unit test.
  • Loading branch information
jkoritzinsky authored May 13, 2020
1 parent 2c569ef commit e23f6e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,5 +1496,12 @@ public void WeakReferenceOfNativeObjectRehydratedAfterWrapperIsCollected()
Assert.True(winrt.TryGetTarget(out _));
GC.KeepAlive(objRef);
}

[Fact]
public void TestUnwrapInspectable()
{
var inspectable = IInspectable.FromAbi(TestObject.ThisPtr);
Assert.True(ComWrappersSupport.TryUnwrapObject(inspectable, out _));
}
}
}
7 changes: 4 additions & 3 deletions WinRT.Runtime/IInspectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum TrustLevel
}

// IInspectable
[ObjectReferenceWrapper(nameof(_obj))]
[Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")]
public class IInspectable
{
Expand Down Expand Up @@ -104,9 +105,9 @@ public unsafe string GetRuntimeClassName(bool noThrow = false)
try
{
var hr = _obj.Vftbl.GetRuntimeClassName(ThisPtr, out __retval);
if (hr != 0)
{
if (noThrow)
if (hr != 0)
{
if (noThrow)
return null;
Marshal.ThrowExceptionForHR(hr);
}
Expand Down

0 comments on commit e23f6e9

Please sign in to comment.