示例#1
0
        /// <summary>
        /// Converts Magic 'Vector' Type to 'dotNetType'
        /// </summary>
        /// <param name="magicVal"></param>
        /// <param name="dotNetType"></param>
        /// <returns></returns>
        private static object convertVectorToDotNet(string magicVal, Type dotNetType)
        {
            Object           retObject   = null;
            VectorType       vector      = new VectorType(magicVal);
            StorageAttribute vecCellAttr = VectorType.getCellsAttr(magicVal);
            int    vecSize   = (int)VectorType.getVecSize(magicVal);
            Type   arrayType = null;
            String vecCellMagicFormat;
            Object vecCellDotNetFormat;

            // get the default conversion Type
            arrayType = getDefaultDotNetTypeForVector(vector);

            if (arrayType != null)
            {
                // construct the arrayObject
                Array arrayObj = ReflectionServices.CreateArrayInstance(arrayType, new int[] { vecSize });

                for (int idx = 0; idx < vecSize; idx++)
                {
                    vecCellMagicFormat  = vector.getVecCell(idx + 1);
                    vecCellDotNetFormat = convertMagicToDotNet(vecCellMagicFormat, vecCellAttr, arrayType);
                    arrayObj.SetValue(vecCellDotNetFormat, idx);
                }

                // perform cast into 'dotNetType'
                retObject = doCast(arrayObj, dotNetType);
            }

            return(retObject);
        }
示例#2
0
        /// <summary>
        /// gets the default dotnet type for vector
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        private static Type getDefaultDotNetTypeForVector(VectorType vector)
        {
            StorageAttribute vecCellAttr = vector.getCellsAttr();
            Type             dotNetType  = null;

            switch (vecCellAttr)
            {
            case StorageAttribute.NUMERIC:
                dotNetType = typeof(Double);
                break;

            case StorageAttribute.ALPHA:
            case StorageAttribute.UNICODE:
                dotNetType = typeof(String);
                break;

            case StorageAttribute.DATE:
                dotNetType = typeof(DateTime);
                break;

            case StorageAttribute.TIME:
                dotNetType = typeof(TimeSpan);
                break;

            case StorageAttribute.BOOLEAN:
                dotNetType = typeof(Boolean);
                break;

            case StorageAttribute.BLOB:
                if (vector.getVecSize() > 0 && BlobType.getContentType(vector.getVecCell(1)) == BlobType.CONTENT_TYPE_BINARY)
                {
                    dotNetType = typeof(Byte[]);
                }
                else
                {
                    dotNetType = typeof(String);
                }
                break;

            case StorageAttribute.BLOB_VECTOR:
                dotNetType = typeof(Array);
                break;

            case StorageAttribute.DOTNET:
                dotNetType = typeof(Object);
                break;
            }

            return(dotNetType);
        }