MonoMobile.Views.ReflectiveCommand.Execute C# (CSharp) Method

Execute() public method

public Execute ( object parameter ) : object
parameter object
return object
		public object Execute(object parameter)
		{
			object result = null;
			
			try
			{
				if (CanExecute(parameter))
				{
					if (_Execute.GetParameters().Any())
						result = _Execute.Invoke(_ViewModel, new object[] { parameter });
					else
						result = _Execute.Invoke(_ViewModel, null);
				}
			}
			catch(TargetInvocationException ex)
			{
				throw new Exception(string.Format("{0} method has thrown an exception: {1}", ex.InnerException.TargetSite.Name, ex.InnerException.Message), ex);
			}

			return result;
		}
	}

Usage Example

Beispiel #1
0
        private static CommandBarButtonItem CreateCommandBarButton(object view, MemberInfo member, string title, UIView buttonView, UIBarButtonItemStyle style, UIBarButtonSystemItem?buttonType, BarButtonLocation location)
        {
            CommandBarButtonItem button = null;

            ReflectiveCommand command = null;
            var methodInfo            = member as MethodInfo;

            if (methodInfo != null)
            {
                command = GetCommandForMember(view, member);
            }

            if (!string.IsNullOrEmpty(title))
            {
                button = new CommandBarButtonItem(title, style, (sender, e) => command.Execute(null));
            }
            else if (buttonView != null)
            {
                button = new CommandBarButtonItem(buttonView);
            }
            else
            {
                if (!buttonType.HasValue)
                {
                    buttonType = UIBarButtonSystemItem.Done;
                }

                button       = new CommandBarButtonItem(buttonType.Value, (sender, e) => command.Execute(null));
                button.Style = style;
            }

            command.CommandButton = button;
            button.Enabled        = true;
            button.Location       = location;
            button.Command        = command;

            var orderAttribute = member.GetCustomAttribute <OrderAttribute>();

            if (orderAttribute != null)
            {
                button.Order = orderAttribute.Order;
            }
            else
            {
                button.Order = 0;
            }

            return(button);
        }