示例#1
0
文件: TMap.cs 项目: yimengfan/USharp
        public Dictionary <TKey, TValue> FromNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop)
        {
            IntPtr scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));

            helper.Map = scriptMapAddress;

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;
                Dictionary <TKey, TValue> result = new Dictionary <TKey, TValue>();
                int maxIndex = map->GetMaxIndex();
                for (int i = 0; i < maxIndex; ++i)
                {
                    if (map->IsValidIndex(i))
                    {
                        IntPtr keyPtr, valuePtr;
                        helper.GetPairPtr(i, out keyPtr, out valuePtr);
                        result.Add(
                            keyFromNative(keyPtr, 0, helper.KeyPropertyAddress),
                            valueFromNative(valuePtr, 0, helper.ValuePropertyAddress));
                    }
                }
                return(result);
            }
        }
示例#2
0
文件: TMap.cs 项目: zwywilliam/USharp
        public static IDictionary <TKey, TValue> FromNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop)
        {
            IntPtr           scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));
            FScriptMapHelper helper           = new FScriptMapHelper(prop, scriptMapAddress);

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;
                Dictionary <TKey, TValue> result = new Dictionary <TKey, TValue>();
                int count = map->Count;
                for (int i = 0; i < count; ++i)
                {
                    IntPtr keyPtr, valuePtr;
                    helper.GetPairPtr(i, out keyPtr, out valuePtr);
                    result.Add(
                        keyFromNative(keyPtr, 0, helper.KeyPropertyAddress),
                        valueFromNative(valuePtr, 0, helper.ValuePropertyAddress));
                }
                return(result);
            }
        }