/// <summary>
        /// Fixes up a return value to return to FoxPro 
        /// based on its type. Fixes up some values to
        /// be type safe for FoxPro and others are returned
        /// as wrappers (ComArray, ComGuid)
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static object FixupReturnValue(object val)
        {
            if (val == null)
                return null;

            // *** Need to figure out a solution for value types
            Type type = val.GetType();

            if (type == typeof(Guid))
            {
                ComGuid guid = new ComGuid();
                guid.Guid = (Guid)val;
                return guid;
            }
            if (type == typeof(long) || type == typeof(Int64) )
                return Convert.ToDecimal(val);
            if (type == typeof (char))
                return val.ToString();
            if (type == typeof(byte[]))
            {
                // this ensures byte[] is not treated like an array (below)
                // but returned as binary data
            }
                // FoxPro can't deal with DBNull as it's a value type
            else if (type == typeof(DBNull))
            {
                val = null;
            }
            else if (type.IsArray)
            {
                ComArray comArray = new ComArray();
                comArray.Instance = val as Array;
                return comArray;
            }
            //else if (type.IsValueType)
            //{
            //    var comValue = new ComValue();
            //    comValue.Value = val;
            //    return comValue;
            //}

            return val;
        }
Example #2
0
        /// <summary>
        /// Fixes up a return value based on its type
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private object FixupReturnValue(object val)
        {
            if (val == null)
                return null;

            // *** Need to figure out a solution for value types
            Type type = val.GetType();

            if (type == typeof(Guid))
            {
                ComGuid guid = new ComGuid();
                guid.Guid = (Guid)val;
                return guid;
            }
            else if (type == typeof(long) || type == typeof(Int64) )
                return Convert.ToDecimal(val);
            else if (type == typeof(byte[]))
            {
                // this ensures byte[] is not treated like an array (below)
            }
            // FoxPro can't deal with DBNull as it's a value type
            else if (type == typeof(DBNull))
            {
                val = null;
            }
            else if (type.IsArray)
            {
                ComArray comArray = new ComArray();
                comArray.Instance = val as Array;
                return comArray;
            }

            return val;
        }