Esempio n. 1
0
        public static unsafe void TestByRefLikeRefReturn()
        {
            ByRefLike  brl  = new ByRefLike();
            ByRefLike *pBrl = &brl;
            MethodInfo mi   = typeof(TestClass <int>).GetMethod(nameof(TestClass <int> .ByRefLikeRefReturningMethod));

            try
            {
                // Don't use Assert.Throws because that will make a lambda and invalidate the pointer
                object o = mi.Invoke(null, new object[] { Pointer.Box(pBrl, typeof(ByRefLike *)) });

                // If this is reached, it means `o` is a boxed byref-like type. That's a GC hole right there.
                throw new Xunit.Sdk.XunitException("Boxed a byref-like type.");
            }
            catch (NotSupportedException)
            {
                // We expect a NotSupportedException from the Invoke call. Methods returning byref-like types by reference
                // are not reflection invokable.
            }
        }
Esempio n. 2
0
 public static unsafe ref ByRefLike ByRefLikeRefReturningMethod(ByRefLike *a) => ref *a;