コード例 #1
0
        public static bool MakeViewModelDataBindingEvent(ViewController rViewController, EventBinding rEventBinding)
        {
            if (string.IsNullOrEmpty(rEventBinding.ViewModelMethod))
            {
                return(false);
            }

            var rViewModelMethods = rEventBinding.ViewModelMethod.Split('/');

            if (rViewModelMethods.Length < 2)
            {
                return(false);
            }

            var rViewModelEventClass = rViewModelMethods[0];
            var rViewModelEventName  = rViewModelMethods[1];

            var rBindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
            var rMethodInfo   = rViewController.GetType().GetMethods(rBindingFlags)
                                .Where(method => method.Name.Equals(rViewModelEventName)
                                       ).FirstOrDefault();

            if (rMethodInfo != null)
            {
                Action <EventArg> rActionDelegate = (rEventArg) => { rMethodInfo.Invoke(rViewController, new object[] { rEventArg }); };
                rEventBinding.InitEventWatcher(rActionDelegate);
            }
            else
            {
                Debug.LogErrorFormat("Can not find Method: {0},{1} in ViewController.", rEventBinding, rEventBinding.ViewModelMethod);
                return(false);
            }
            return(true);
        }