-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
GenericsTest.NullableF.cs
50 lines (38 loc) · 1.81 KB
/
GenericsTest.NullableF.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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;
unsafe partial class GenericsNative
{
[DllImport(nameof(GenericsNative))]
public static extern float? GetNullableF(bool hasValue, float value);
[DllImport(nameof(GenericsNative))]
public static extern void GetNullableFOut(bool hasValue, float value, out float? pValue);
[DllImport(nameof(GenericsNative), EntryPoint = "GetNullableFPtr")]
public static extern ref readonly float? GetNullableFRef(bool hasValue, float value);
[DllImport(nameof(GenericsNative))]
public static extern float? AddNullableF(float? lhs, float? rhs);
[DllImport(nameof(GenericsNative))]
public static extern float? AddNullableFs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] float?[] pValues, int count);
[DllImport(nameof(GenericsNative))]
public static extern float? AddNullableFs(in float? pValues, int count);
}
unsafe partial class GenericsTest
{
private static void TestNullableF()
{
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetNullableF(true, 1.0f));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.GetNullableFOut(true, 1.0f, out float? value3));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddNullableF(default, default));
float?[] values = new float?[] {
default,
default,
default,
default,
default
};
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddNullableFs(values, values.Length));
Assert.Throws<MarshalDirectiveException>(() => GenericsNative.AddNullableFs(in values[0], values.Length));
}
}