-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapStringVector.cs
55 lines (48 loc) · 1.91 KB
/
WrapStringVector.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
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;
namespace AlureWrapper
{
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
internal class WrapStringVector : SafeHandleZeroOrMinusOneIsInvalid
{
#region Extern
[DllImport("alure-c-interface", CallingConvention = CallingConvention.Cdecl)]
private static extern void wrapStringVector_destroy(IntPtr dm);
[DllImport("alure-c-interface", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern UInt64 wrapStringVector_getSize(IntPtr dm);
[DllImport("alure-c-interface", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr wrapStringVector_getAt(IntPtr dm, UInt64 position);
#endregion Extern
public WrapStringVector() : base(true) { }
public WrapStringVector(IntPtr dm, bool ownsHandle = false) : base(ownsHandle)
{
SetHandle(dm);
}
public string[] ToStrings()
{
var list = new List<string>();
UInt64 size = wrapStringVector_getSize(handle);
for (UInt64 i = 0; i < size; ++i)
{
using (var tmp = new WrapString(wrapStringVector_getAt(handle, i)))
{
list.Add(tmp.ToString());
}
}
return list.ToArray();
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
wrapStringVector_destroy(handle);
SetHandleAsInvalid();
handle = IntPtr.Zero;
return true;
}
}
}