예제 #1
0
        /// <summary>
        /// Sets the Value property from a CreateInstance call. Useful for
        /// value types that can't be passed back to FoxPro.
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="parms"></param>
        public void SetValueFromCreateInstance(string typeName, ComArray parms)
        {
            var list = new List <object>();

            if (parms != null && parms.Instance != null)
            {
                foreach (object item in parms.Instance as IEnumerable)
                {
                    list.Add(item);
                }
            }

            SetValueFromCreateInstance_Internal(typeName, list.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Sets the Value property from a method call that passes it's positional arguments
        /// as an array. This version accepts a ComArray directly so it can be called
        /// directly from FoxPro with a ComArray instance
        /// </summary>
        /// <param name="objectRef">Object instance</param>
        /// <param name="method">Method to call</param>
        /// <param name="parms">An array of the parameters passed (use ComArray and InvokeMethod)</param>
        public void SetValueFromInvokeMethod(object objectRef, string method, ComArray parms)
        {
            var list = new List <object>();

            if (parms.Instance != null)
            {
                foreach (object item in parms.Instance as IEnumerable)
                {
                    list.Add(item);
                }
            }

            SetValueFromInvokeMethod(objectRef, method, list.ToArray());
        }
예제 #3
0
        /// <summary>
        /// Invokes a static method with the passed parameters and sets the Value property
        /// from the result value.
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="method"></param>
        /// <param name="parms"></param>
        public void SetValueFromInvokeStaticMethod(string typeName, string method, ComArray parms)
        {
            wwDotNetBridge bridge = new wwDotNetBridge();
            var            list   = new List <object>();

            if (parms.Instance != null)
            {
                foreach (object item in parms.Instance as IEnumerable)
                {
                    list.Add(item);
                }
            }

            Value = bridge.InvokeStaticMethod_Internal(typeName, method, list.ToArray());
        }
예제 #4
0
        /// <summary>
        /// Creates a generic type and stores it on the Value object.
        /// </summary>
        /// <param name="genericTypeName">Name of the base generic type. Example: System.Collections.Generics.List</param>
        /// <param name="typeNames">A ComArray of string type names that are the generic parameters</param>
        /// <param name="constructorParms"></param>
        public void SetValueFromCreateGenericInstance(string genericTypeName, ComArray typeNames, ComArray constructorParms)
        {
            var genericTypes = wwDotNetBridge.FixupParameter(typeNames) as string[];

            object[] parameters = wwDotNetBridge.FixupParameter(constructorParms) as object[];

            object parmList = null;

            if (parameters.Length > 0)
            {
                parmList = parameters;
            }

            if (genericTypes == null || genericTypes.Length == 0)
            {
                throw new ArgumentException("Must pass at least one generic type argument to CreateGenericType");
            }

            var typename = genericTypeName + "`" + genericTypes.Length + "[";

            foreach (string typeName in genericTypes)
            {
                typename += typeName + ",";
            }
            typename = typename.TrimEnd(',') + "]";


            var    type = Type.GetType(typename);
            object instance;

            if (parmList == null)
            {
                instance = Activator.CreateInstance(type);
            }
            else
            {
                instance = type.Assembly.CreateInstance(typename, false, BindingFlags.Default, null, parameters, null, null);
            }

            Value = instance;
        }
예제 #5
0
        /// <summary>
        /// Creates an instance of an array
        /// </summary>
        /// <param name="arrayTypeString"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public ComArray CreateArray(string arrayTypeString)
        {
            SetError();

            Type type = null;
            type = ReflectionUtils.GetTypeFromName(arrayTypeString);

            if (type == null)
            {
                SetError("Invalid type for array: " + arrayTypeString);
                return null;
            }

            ComArray comArray = new ComArray();

            // *** Create instance and assign
            Array ar = Array.CreateInstance(type, 0);

            // *** assign the item passed in
            //ar.SetValue(item, 0);
            comArray.Instance = ar;

            return comArray;
        }
예제 #6
0
        /// <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;
        }
예제 #7
0
        /// <summary>
        /// Invokes a static method with the passed parameters and sets the Value property
        /// from the result value.
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="method"></param>
        /// <param name="parms"></param>
        public void SetValueFromInvokeStaticMethod(string typeName, string method, ComArray parms)
        {
            wwDotNetBridge bridge = new wwDotNetBridge();
            var list = new List<object>();
            if (parms.Instance != null)
                foreach (object item in parms.Instance as IEnumerable)
                    list.Add(item);

            Value = bridge.InvokeStaticMethod_Internal(typeName, method, list.ToArray());
        }
예제 #8
0
        /// <summary>
        /// Sets the Value property from a method call that passes it's positional arguments
        /// as an array. This version accepts a ComArray directly so it can be called
        /// directly from FoxPro with a ComArray instance
        /// </summary>
        /// <param name="objectRef">Object instance</param>
        /// <param name="method">Method to call</param>
        /// <param name="parms">An array of the parameters passed (use ComArray and InvokeMethod)</param>
        public void SetValueFromInvokeMethod(object objectRef, string method, ComArray parms)
        {
            var list = new List<object>();
            if (parms.Instance != null)
                foreach (object item in parms.Instance as IEnumerable)
                    list.Add(item);

            SetValueFromInvokeMethod(objectRef, method, list.ToArray());
        }
예제 #9
0
        /// <summary>
        /// Sets the Value property from a CreateInstance call. Useful for
        /// value types that can't be passed back to FoxPro.
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="parms"></param>
        public void SetValueFromCreateInstance(string typeName, ComArray parms)
        {
            var list = new List<object>();
            if (parms.Instance != null)
                foreach(object item in parms.Instance as IEnumerable)
                    list.Add(item);

              SetValueFromCreateInstance(typeName, list.ToArray());
        }
예제 #10
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;
        }