Пример #1
0
        /// <summary>
        /// Handles the conversion of Objects (both MagicTypes and DotNet) into the specified type.
        /// It works only for an ExpVal object (for MagicType) or a DotNet object.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="dotNetType"></param>
        /// <returns></returns>
        public static Object doCast(Object obj, Type dotNetType)
        {
            Object objToCast;
            Object castedObj = null;

            try
            {
                if (GuiExpressionEvaluator.isExpVal(obj))
                {
                    objToCast = GuiExpressionEvaluator.convertExpValToDotNet(obj, dotNetType);
                }
                else
                {
                    objToCast = obj;
                }

                castedObj = ReflectionServices.DynCast(objToCast, dotNetType);
            }
            catch (Exception exception)
            {
                DNException dnException = Manager.GetCurrentRuntimeContext().DNException;
                dnException.set(exception);
                throw dnException;
            }

            return(castedObj);
        }
Пример #2
0
        /// <summary>
        /// converts dotnet object into a corrosponding magic value.
        /// </summary>
        /// <param name="dotNetObj"></param>
        /// <param name="magicType"></param>
        /// <returns></returns>
        public static String convertDotNetToMagic(Object dotNetObj, StorageAttribute magicType)
        {
            String retStr = "";

            if (dotNetObj == null || magicType == StorageAttribute.NONE)
            {
                return(retStr);
            }

            try
            {
                switch (magicType)
                {
                case StorageAttribute.NUMERIC:
                    // conversion to NUMERIC Magic type
                    retStr = convertDotNetToNumeric(dotNetObj);
                    break;

                case StorageAttribute.ALPHA:
                case StorageAttribute.UNICODE:
                    // conversion to ALPHA UNICODE Magic type
                    retStr = convertDotNetToAlphaUnicode(dotNetObj);
                    break;

                case StorageAttribute.DATE:
                    // conversion to DATE Magic type
                    retStr = convertDotNetToDate(dotNetObj);
                    break;

                case StorageAttribute.TIME:
                    // conversion to TIME Magic type
                    retStr = convertDotNetToTime(dotNetObj);
                    break;

                case StorageAttribute.BOOLEAN:
                    // conversion to LOGICAL BOOLEAN Magic type
                    retStr = convertDotNetToLogicalBoolean(dotNetObj);
                    break;

                case StorageAttribute.BLOB:
                    // conversion to BLOB Magic type
                    retStr = convertDotNetToBlob(dotNetObj);
                    break;

                case StorageAttribute.BLOB_VECTOR:
                    // conversion to VECTOR Magic type
                    retStr = convertDotNetToVector(dotNetObj);
                    break;

                case StorageAttribute.DOTNET:
                    // conversion to DOTNET Magic type - not allowed. This should be done only in ExpValToMgVal.
                    break;

                default:
                    break;
                }
            }
            catch (Exception exception)
            {
                DNException dnException = Manager.GetCurrentRuntimeContext().DNException;
                dnException.set(exception);
                throw dnException;
            }

            return(retStr);
        }
Пример #3
0
        /// <summary>
        /// converts magic value into a corrosponding dotnet object, as defined by the table below
        ///
        /// 1. NUMERIC to - SByte, Byte, Int16, Uint16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Decimal, Single, Double, Float
        /// 2. ALPHA, UNICODE to - Char, Char[], String, StringBuilder
        /// 3. DATE to - DateTime
        /// 4. TIME to - DateTime, TimeSpan
        /// 5. LOGICAL to - Boolean
        /// 6. BLOB to - Byte, Byte[], Char, Char[], String, StringBuilder
        /// 7. VECTOR to - jagged Array
        /// 8. DOTNET to - Object
        ///
        /// </summary>
        /// <param name="magicVal">the string value in magic type</param>
        /// <param name="magicType">Type of magicVal</param>
        /// <param name="dotNetType">DotNet type</param>
        /// <returns></returns>
        public static Object convertMagicToDotNet(String magicVal, StorageAttribute magicType, Type dotNetType)
        {
            Object retObject = null;

            // if the dotnettype to convert is System.Object, we should get convert magicVal to default
            // dotnet type based on 'magicVal'.
            if (dotNetType == typeof(Object))
            {
                dotNetType = getDefaultDotNetTypeForMagicType(magicVal, magicType);
            }

            try
            {
                switch (magicType)
                {
                case StorageAttribute.NUMERIC:
                    // NUMERIC Magic type conversion
                    retObject = convertNumericToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.ALPHA:
                case StorageAttribute.UNICODE:
                    // ALPHA UNICODE Magic type conversion
                    retObject = convertAlphaUnicodeToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.DATE:
                    // DATE Magic type conversion
                    retObject = convertDateToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.TIME:
                    // TIME Magic type conversion
                    retObject = convertTimeToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.BOOLEAN:
                    // LOGICAL BOOLEAN Magic type conversion
                    retObject = convertLogicalBooleanToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.BLOB:
                    // BLOB Magic type conversion
                    retObject = convertBlobToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.BLOB_VECTOR:
                    // VECTOR Magic type conversion
                    retObject = convertVectorToDotNet(magicVal, dotNetType);
                    break;

                case StorageAttribute.DOTNET:
                    // DOTNET Magic type conversion
                    retObject = convertDotNetMagicToDotNet(magicVal, dotNetType);
                    break;

                default:
                    break;
                }
            }
            catch (Exception exception)
            {
                DNException dnException = Manager.GetCurrentRuntimeContext().DNException;
                dnException.set(exception);
                throw dnException;
            }

            return(retObject);
        }