-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Delegates.cs
35 lines (27 loc) · 1.22 KB
/
Delegates.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.InteropServices;
using Xunit;
using static DisabledRuntimeMarshallingNative;
namespace DisabledRuntimeMarshalling.PInvokeAssemblyMarshallingEnabled;
public unsafe class DelegatesFromExternalAssembly
{
[Fact]
public static void StructWithDefaultNonBlittableFields()
{
short s = 42;
bool b = true;
var callback = Marshal.GetDelegateForFunctionPointer<CheckStructWithShortAndBoolCallback>((IntPtr)DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolCallback());
Assert.False(callback(new StructWithShortAndBool(s, b), s, b));
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public static void StructWithDefaultNonBlittableFields_MarshalAsInfo()
{
short s = 41;
bool b = true;
var callback = Marshal.GetDelegateForFunctionPointer<CheckStructWithShortAndBoolWithMarshalAsAndVariantBoolCallback>((IntPtr)DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolWithVariantBoolCallback());
Assert.True(callback(new StructWithShortAndBoolWithMarshalAs(s, b), s, b));
}
}