예제 #1
0
        //private PersistentListenerMode[] modes;

        public DataBindingCall(object target, MethodInfo method, string argument)
        {
            var parameters = method.GetParameters();
            var count      = parameters.Length;

            if (count == 0 || count > 4)
            {
                Debug.LogError(string.Format("Expression \"{1}\" is invalid parameters size({0})", count, argument));
                return;
            }
            _parser.Parser(argument);
            _expression = _parser.rootExpression;
            if (_expression == null)
            {
                Debug.LogError(string.Format("Expression parsing error! \"{0}\"", argument));
                return;
            }
            if (_expression.Length != count)
            {
                Debug.LogError(string.Format("Expression \"{2}\" is invalid parameters size({0}). Expected size is {1}", _expression.Length, count, argument));
                _expression = null;
                return;
            }

            types = new Type[count];
            for (var i = 0; i < count; ++i)
            {
                types[i] = parameters[i].ParameterType;
            }
            Type generic;

            if (count == 1)
            {
                generic = typeof(InvokableCall <>);
            }
            else if (count == 2)
            {
                generic = typeof(InvokableCall <,>);
            }
            else if (count == 3)
            {
                generic = typeof(InvokableCall <, ,>);
            }
            else
            {
                generic = typeof(InvokableCall <, , ,>);
            }

            var specific = generic.MakeGenericType(types);
            var ci       = specific.GetConstructor(new[] { typeof(Object), typeof(MethodInfo) });

            _runtimeCall = ci.Invoke(new object[] { target, method }) as BaseInvokableCall;
        }
예제 #2
0
        public void Invoke(object value)
        {
            if (_runtimeCall == null)
            {
                _runtimeCall = GetRuntimeCall();
            }

            if (_runtimeCall != null)
            {
                switch (mode)
                {
                case PersistentListenerMode.Object:
                    /*if (!(value is float))
                     * {
                     *  return;
                     * }*/
                    break;

                case PersistentListenerMode.Float:
                    if (!(value is float))
                    {
                        value = Convert.ToDouble(value);
                    }
                    break;

                case PersistentListenerMode.Int:
                    if (!(value is int))
                    {
                        value = Convert.ToInt32(value);
                    }
                    break;

                case PersistentListenerMode.String:
                    if (!(value is string))
                    {
                        value = value.ToString();
                    }
                    break;

                case PersistentListenerMode.Bool:
                    if (value is string)
                    {
                        value = (value != "flase" && value != "0");
                    }
                    else
                    {
                        value = Convert.ToBoolean(value);
                    }
                    break;
                }
                _runtimeCall.Invoke(value);
            }
        }