Пример #1
0
        public IMvxCommandCollection BuildCollectionFor(object owner)
        {
            var toReturn = new MvxCommandCollection(owner);

            CreateCommands(owner, toReturn);
            return(toReturn);
        }
        protected virtual void CreateCommand(object owner, MvxCommandCollection collection, MethodInfo commandMethod, string commandName, bool hasParameter)
        {
            var canExecuteProperty = CanExecutePropertyInfo(owner.GetType(), commandMethod);

            var helper = hasParameter
                             ? (IMvxCommandBuilder)new MvxParameterizedCommandBuilder(commandMethod, canExecuteProperty)
                             : new MvxCommandBuilder(commandMethod, canExecuteProperty);

            var command = helper.ToCommand(owner);
            collection.Add(command, commandName, helper.CanExecutePropertyName);
        }
Пример #3
0
        protected virtual void CreateCommand(object owner, MvxCommandCollection collection, MethodInfo commandMethod, string commandName, bool hasParameter)
        {
            var canExecuteProperty = CanExecutePropertyInfo(owner.GetType(), commandMethod);

            var helper = hasParameter
                             ? (IMvxCommandBuilder) new MvxParameterizedCommandBuilder(commandMethod, canExecuteProperty)
                             : new MvxCommandBuilder(commandMethod, canExecuteProperty);

            var command = helper.ToCommand(owner);

            collection.Add(command, commandName, helper.CanExecutePropertyName);
        }
        protected virtual void CreateCommands(object owner, MvxCommandCollection toReturn)
        {
            var commandMethods =
                from method in
                owner.GetType()
                .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)
                let parameterCount = method.GetParameters().Count()
                                     where parameterCount <= 1
                                     let commandName = GetCommandNameOrNull(method)
                                                       where !string.IsNullOrEmpty(commandName)
                                                       select new { Method = method, CommandName = commandName, HasParameter = parameterCount > 0 };

            foreach (var item in commandMethods)
            {
                CreateCommand(owner, toReturn, item.Method, item.CommandName, item.HasParameter);
            }
        }
        protected virtual void CreateCommands(object owner, MvxCommandCollection toReturn)
        {
            var commandMethods =
                from method in
                    owner.GetType()
                         .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)
                let parameterCount = method.GetParameters().Count()
                where parameterCount <= 1
                let commandName = GetCommandNameOrNull(method)
                where !string.IsNullOrEmpty(commandName)
                select new {Method = method, CommandName = commandName, HasParameter = parameterCount > 0};

            foreach (var item in commandMethods)
            {
                CreateCommand(owner, toReturn, item.Method, item.CommandName, item.HasParameter);
            }
        }
 public virtual IMvxCommandCollection BuildCollectionFor(object owner)
 {
     var toReturn = new MvxCommandCollection(owner);
     CreateCommands(owner, toReturn);
     return toReturn;
 }