コード例 #1
0
        public void GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected()
        {
            MethodInfo         targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static);
            NonGenericDelegate d            = (NonGenericDelegate)targetMethod.CreateDelegate(typeof(NonGenericDelegate));

            IntPtr pointer1 = Marshal.GetFunctionPointerForDelegate(d);
            IntPtr pointer2 = Marshal.GetFunctionPointerForDelegate(d);

            Assert.NotEqual(IntPtr.Zero, pointer1);
            Assert.Equal(pointer1, pointer2);
        }
コード例 #2
0
        public void GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected()
        {
            MethodInfo         targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method));
            Delegate           original     = targetMethod.CreateDelegate(typeof(NonGenericDelegate));
            IntPtr             ptr          = Marshal.GetFunctionPointerForDelegate(original);
            NonGenericDelegate d            = Marshal.GetDelegateForFunctionPointer <NonGenericDelegate>(ptr);

            IntPtr pointer1 = Marshal.GetFunctionPointerForDelegate(d);
            IntPtr pointer2 = Marshal.GetFunctionPointerForDelegate(d);

            Assert.NotEqual(IntPtr.Zero, pointer1);
            Assert.Equal(ptr, pointer1);
            Assert.Equal(pointer1, pointer2);
        }