summaryrefslogtreecommitdiff
path: root/modules/mono/glue/cs_files/MarshalUtils.cs
blob: 5d401113392c0436a161ac3a25a163393b73223e (plain)
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
using System;
using System.Collections.Generic;

namespace Godot
{
    internal static class MarshalUtils
    {
        private static Dictionary<object, object> ArraysToDictionary(object[] keys, object[] values)
        {
            Dictionary<object, object> ret = new Dictionary<object, object>();

            for (int i = 0; i < keys.Length; i++)
            {
                ret.Add(keys[i], values[i]);
            }

            return ret;
        }

        private static void DictionaryToArrays(Dictionary<object, object> from, out object[] keysTo, out object[] valuesTo)
        {
            Dictionary<object, object>.KeyCollection keys = from.Keys;
            keysTo = new object[keys.Count];
            keys.CopyTo(keysTo, 0);

            Dictionary<object, object>.ValueCollection values = from.Values;
            valuesTo = new object[values.Count];
            values.CopyTo(valuesTo, 0);
        }

        private static Type GetDictionaryType()
        {
            return typeof(Dictionary<object, object>);
        }
    }
}