Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ObjectReferenceWrapper attribute to enable unwrapping WinRT.IInspectable instances. #273

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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