예제 #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);
            }
        }