Exemplo n.º 1
0
        internal static unsafe T ObjectFromNative <T>(ulong *value)
        {
            if (typeof(T).IsEnum)
            {
                return(NativeHelper <T> .Convert(*value));
            }

            if (typeof(T) == typeof(bool))
            {
                // Return proper boolean values (true if non-zero and false if zero)
                bool valueBool = *value != 0;
                return(NativeHelper <T> .PtrToStructure(new IntPtr(&valueBool)));
            }

            if (typeof(T) == typeof(int) || typeof(T) == typeof(uint) || typeof(T) == typeof(long) || typeof(T) == typeof(ulong) || typeof(T) == typeof(float))
            {
                return(NativeHelper <T> .PtrToStructure(new IntPtr(value)));
            }

            if (typeof(T) == typeof(double))
            {
                return(NativeHelper <T> .Convert(NativeHelper <T> .PtrToStructure(new IntPtr(value))));
            }

            if (typeof(T) == typeof(Vector2) || typeof(T) == typeof(Vector3))
            {
                return(NativeHelper <T> .Convert(*(NativeVector3 *)value));
            }

            throw new InvalidCastException(string.Concat("Unable to cast native value to object of type '", typeof(T), "'"));
        }