예제 #1
0
        private static unsafe T WrapElement(IntPtr memberPointer)
        {
            if (ourCachedInstanceCtor == null)
            {
                ourCachedInstanceCtor = typeof(T).GetConstructor(new[] { typeof(IntPtr) });
            }

            if (ourElementIsValueType)
            {
                return((T)ourCachedInstanceCtor.Invoke(new object[]
                                                       { IL2CPP.il2cpp_value_box(Il2CppClassPointerStore <T> .NativeClassPtr, memberPointer) }));
            }

            var referencePointer = *(IntPtr *)memberPointer;

            if (referencePointer == IntPtr.Zero)
            {
                return(null);
            }

            if (typeof(Il2CppObjectBase).IsAssignableFrom(typeof(T)))
            {
                var typePtr           = Il2CppClassPointerStore <T> .NativeClassPtr;
                var referenceClassPtr = IL2CPP.il2cpp_object_get_class(referencePointer);
                if (RuntimeSpecificsStore.IsInjected(typePtr) && IL2CPP.il2cpp_class_is_assignable_from(typePtr, referenceClassPtr))
                {
                    return(ClassInjectorBase.GetMonoObjectFromIl2CppPointer(referencePointer) as T);
                }
            }

            return((T)ourCachedInstanceCtor.Invoke(new object[] { referencePointer }));
        }
        private static unsafe T WrapElement(IntPtr memberPointer)
        {
            if (ourCachedInstanceCtor == null)
            {
                ourCachedInstanceCtor = typeof(T).GetConstructor(new[] { typeof(IntPtr) });
            }

            if (ourElementIsValueType)
            {
                return((T)ourCachedInstanceCtor.Invoke(new object[]
                                                       { IL2CPP.il2cpp_value_box(Il2CppClassPointerStore <T> .NativeClassPtr, memberPointer) }));
            }

            var referencePointer = *(IntPtr *)memberPointer;

            if (referencePointer == IntPtr.Zero)
            {
                return(null);
            }

            return((T)ourCachedInstanceCtor.Invoke(new object[] { referencePointer }));
        }