csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
using System.Runtime.InteropServices;
|
|
|
|
namespace Avalonia.Native.Interop
|
|
{
|
|
unsafe partial class IAvnString
|
|
{
|
|
private string _managed;
|
|
private byte[] _bytes;
|
|
|
|
public string String
|
|
{
|
|
get
|
|
{
|
|
if (_managed == null)
|
|
{
|
|
var ptr = Pointer();
|
|
if (ptr == null)
|
|
return null;
|
|
_managed = System.Text.Encoding.UTF8.GetString((byte*)ptr.ToPointer(), Length());
|
|
}
|
|
|
|
return _managed;
|
|
}
|
|
}
|
|
|
|
public byte[] Bytes
|
|
{
|
|
get
|
|
{
|
|
if (_bytes == null)
|
|
{
|
|
_bytes = new byte[Length()];
|
|
Marshal.Copy(Pointer(), _bytes, 0, _bytes.Length);
|
|
}
|
|
|
|
return _bytes;
|
|
}
|
|
}
|
|
|
|
public override string ToString() => String;
|
|
}
|
|
|
|
partial class IAvnStringArray
|
|
{
|
|
public string[] ToStringArray()
|
|
{
|
|
var arr = new string[Count];
|
|
for(uint c = 0; c<arr.Length;c++)
|
|
using (var s = Get(c))
|
|
arr[c] = s.String;
|
|
return arr;
|
|
}
|
|
}
|
|
}
|
|
|