Пример #1
0
        public Array ToArray(Type arrayType)
        {
            JSNumberType subType     = 0;
            JSValueType  type        = JSValueType.Number;
            Type         elementType = arrayType.GetElementType();

            if (typeof(sbyte) == elementType)
            {
                subType = JSNumberType.SByte;
            }
            else if (typeof(byte) == elementType)
            {
                subType = JSNumberType.Byte;
            }
            else if (typeof(short) == elementType)
            {
                subType = JSNumberType.Int16;
            }
            else if (typeof(ushort) == elementType)
            {
                subType = JSNumberType.UInt16;
            }
            else if (typeof(int) == elementType)
            {
                subType = JSNumberType.Int32;
            }
            else if (typeof(uint) == elementType)
            {
                subType = JSNumberType.UInt32;
            }
            else if (typeof(long) == elementType)
            {
                subType = JSNumberType.Int64;
            }
            else if (typeof(ulong) == elementType)
            {
                subType = JSNumberType.UInt64;
            }
            else if (typeof(float) == elementType)
            {
                subType = JSNumberType.Single;
            }
            else if (typeof(double) == elementType)
            {
                subType = JSNumberType.Double;
            }
            else if (typeof(bool) == elementType)
            {
                type = JSValueType.Boolean;
            }
            else if (typeof(string) == elementType)
            {
                type = JSValueType.String;
            }
            return(Entry.Parameters.ToArray(this.Handle, this.Index, type, subType));
        }
Пример #2
0
            static internal Array ToArray(IntPtr handle, int index, JSValueType type, JSNumberType subType)
            {
                if (JSValueType.String == type)
                {
                    int      count = General_Typescript_Parameter_GetArrayLength(sInstance.Context, handle, index);
                    string[] array = new string[count];
                    foreach (int i in Enumerable.Range(0, count))
                    {
#if UNITY_STANDALONE_WIN || UNITY_ANDROID
                        array[i] = Marshal.PtrToStringAnsi(General_Typescript_Parameter_GetArrayString(sInstance.Context, handle, index, i));
#else
                        array[i] = General_Typescript_Parameter_GetArrayString(sInstance.Context, handle, index, i);
#endif
                    }
                    return(array);
                }
                else
                {
                    IntPtr result = General_Typescript_Parameter_ToArray(sInstance.Context, handle, index, (int)type, (int)subType);
                    int    count  = Marshal.ReadInt32(result);
                    result += sizeof(int);
                    if (JSValueType.Boolean == type)
                    {
                        bool[] array = new bool[count];
                        foreach (int i in Enumerable.Range(0, count))
                        {
                            array[i] = 0 != Marshal.ReadByte(result);
                            result  += sizeof(byte);
                        }
                        return(array);
                    }
                    else if (JSValueType.Number == type)
                    {
                        Array array = null;
                        switch (subType)
                        {
                        case JSNumberType.SByte:
                            sbyte[] arraySByte = new sbyte[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arraySByte[i] = (sbyte)Marshal.ReadByte(result);
                                result       += sizeof(byte);
                            }
                            array = arraySByte;
                            break;

                        case JSNumberType.Byte:
                            byte[] arrayByte = new byte[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayByte[i] = Marshal.ReadByte(result);
                                result      += sizeof(byte);
                            }
                            array = arrayByte;
                            break;

                        case JSNumberType.Int16:
                            short[] arrayInt16 = new short[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayInt16[i] = (short)Marshal.ReadInt16(result);
                                result       += sizeof(short);
                            }
                            array = arrayInt16;
                            break;

                        case JSNumberType.UInt16:
                            ushort[] arrayUInt16 = new ushort[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayUInt16[i] = (ushort)Marshal.ReadInt16(result);
                                result        += sizeof(ushort);
                            }
                            array = arrayUInt16;
                            break;

                        case JSNumberType.Int32:
                            int[] arrayInt32 = new int[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayInt32[i] = (int)Marshal.ReadInt32(result);
                                result       += sizeof(int);
                            }
                            array = arrayInt32;
                            break;

                        case JSNumberType.UInt32:
                            uint[] arrayUInt32 = new uint[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayUInt32[i] = (uint)Marshal.ReadInt32(result);
                                result        += sizeof(uint);
                            }
                            array = arrayUInt32;
                            break;

                        case JSNumberType.Int64:
                            long[] arrayInt64 = new long[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayInt64[i] = (long)Marshal.ReadInt64(result);
                                result       += sizeof(long);
                            }
                            array = arrayInt64;
                            break;

                        case JSNumberType.UInt64:
                            ulong[] arrayUInt64 = new ulong[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayUInt64[i] = (ulong)Marshal.ReadInt64(result);
                                result        += sizeof(ulong);
                            }
                            array = arrayUInt64;
                            break;

                        case JSNumberType.Single:
                            float[] arraySingle = new float[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arraySingle[i] = (float)Marshal.PtrToStructure <System.Single>(result);
                                result        += sizeof(float);
                            }
                            array = arraySingle;
                            break;

                        case JSNumberType.Double:
                            double[] arrayDouble = new double[count];
                            foreach (int i in Enumerable.Range(0, count))
                            {
                                arrayDouble[i] = (double)Marshal.PtrToStructure <System.Double>(result);
                                result        += sizeof(double);
                            }
                            array = arrayDouble;
                            break;
                        }
                        return(array);
                    }
                }
                return(null);
            }