Пример #1
0
        /// <summary>
        /// Converts 'dotNetObj' to 'Vector' Magic type
        /// </summary>
        /// <param name="dotNetObj"></param>
        /// <returns></returns>
        private static string convertDotNetToVector(object dotNetObj)
        {
            String retObject  = "";
            Type   dotNetType = dotNetObj.GetType();

            if (dotNetType.IsArray)
            {
                Array            arrObj      = (Array)dotNetObj;
                Type             arrCellType = arrObj.GetType().GetElementType();
                StorageAttribute vecCellType = getDefaultVecCellTypeForDotNet(arrCellType);

                if (vecCellType != StorageAttribute.NONE)
                {
                    VectorType vector;
                    String[]   magicVals = new String[arrObj.Length];
                    long       maxLength = 0;

                    // convert each element of array into magic equivalent and store it in temp string array.
                    for (int idx = 0; idx < arrObj.Length; idx++)
                    {
                        magicVals[idx] = convertDotNetToMagic(arrObj.GetValue(idx), vecCellType);

                        // evaluate max length
                        if (magicVals[idx].Length > maxLength)
                        {
                            maxLength = magicVals[idx].Length;
                        }
                    }

                    if (vecCellType == StorageAttribute.BLOB)
                    {
                        maxLength = 28; // length for a blob is always 28
                    }
                    // find cellContentType and create a vector
                    char cellContentType = BlobType.CONTENT_TYPE_UNKNOWN;
                    if (vecCellType == StorageAttribute.BLOB && magicVals.Length > 0)
                    {
                        cellContentType = BlobType.getContentType(magicVals[0]);
                    }
                    vector = new VectorType(vecCellType, cellContentType, "", true, true, maxLength);

                    // set the temp string array into vector
                    for (int idx = 0; idx < arrObj.Length; idx++)
                    {
                        vector.setVecCell(idx + 1, magicVals[idx], false);
                    }

                    // get the flattened string
                    retObject = vector.ToString();
                }
            }

            return(retObject);
        }