Exemplo n.º 1
0
        static object ObtainParameter(InvokeParameters invokeParameters, object parameter)
        {
            if (parameter is ReflectionParameter)
            {
                ReflectionParameter rp = (ReflectionParameter)parameter;
                return(invokeParameters[rp.Name]);
            }

            return(parameter);
        }
Exemplo n.º 2
0
        public static object InvokeMethod(UiController controller, object binding, object definition, InvokeParameters invokeParameters)
        {
            MethodName method = (MethodName)definition;

            string name = method.Name;

            if (name.StartsWith(":"))
            {
                name       = name.Substring(1);
                controller = controller.Parent;
            }

            object context = method.Binding ? binding : controller;

            object[] parameters = new object[method.Parameters.Length];

            for (int idx = 0; idx < parameters.Length; ++idx)
            {
                parameters[idx] = ObtainParameter(invokeParameters, method.Parameters[idx]);
            }

            MethodInfo[] infos = context.GetType().GetMethods();

            if (infos != null)
            {
                foreach (var info in infos)
                {
                    if (info.Name == name)
                    {
                        ParameterInfo[] methodParams = info.GetParameters();

                        if (parameters.Length == methodParams.Length)
                        {
                            return(info.Invoke(context, parameters));
                        }
                    }
                }
            }

            throw new Exception(String.Format("Cannot find method: {0}({1})", name, parameters.ToString()));
        }
Exemplo n.º 3
0
        public static object GetFieldValue(UiController controller, object binding, object definition, InvokeParameters invokeParameters)
        {
            FieldName field = (FieldName)definition;

            object context = field.Binding ? binding : controller;

            if (field.Name == "*")
            {
                return(context);
            }

            string name = field.Name;

            if (name.StartsWith(":"))
            {
                name       = name.Substring(1);
                controller = controller.Parent;
            }

            int[] indices = null;

            if (field.Parameters != null)
            {
                indices = new int[field.Parameters.Length];

                for (int idx = 0; idx < indices.Length; ++idx)
                {
                    indices[idx] = (int)ObtainParameter(invokeParameters, field.Parameters[idx]);
                }
            }

            PropertyInfo info = context.GetType().GetProperty(name);

            if (info != null)
            {
                object value = info.GetValue(context, null);

                if (indices != null)
                {
                    if (value is Array)
                    {
                        return((value as Array).GetValue(indices));
                    }

                    throw new Exception(String.Format("Value is not an array: {0}[{1}]", name, indices.ToString()));
                }
                else
                {
                    return(value);
                }
            }
            else
            {
                FieldInfo finfo = context.GetType().GetField(name);

                if (finfo != null)
                {
                    object value = finfo.GetValue(context);

                    if (indices != null)
                    {
                        if (value is Array)
                        {
                            return((value as Array).GetValue(indices));
                        }

                        throw new Exception(String.Format("Value is not an array: {0}[{1}]", name, indices.ToString()));
                    }
                    else
                    {
                        return(value);
                    }
                }
            }

            throw new Exception(String.Format("Cannot find field: {0}{1}", field.Name, indices != null ? '[' + indices.ToString() + ']' : ""));
        }
Exemplo n.º 4
0
        public static T InvokeMethod <T>(UiController controller, object binding, object definition, InvokeParameters invokeParameters)
        {
            object result = InvokeMethod(controller, binding, definition, invokeParameters);

            return((T)Convert.ChangeType(result, typeof(T)));
        }