Exemple #1
0
        public static IMvxBundle SaveStateBundle(this IMvxViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var toReturn = new MvxBundle();
            var methods  = viewModel.GetType()
                           .GetMethods()
                           .Where(m => m.Name == "SaveState" && m.ReturnType != typeof(void) && !m.GetParameters().Any());

            foreach (var methodInfo in methods)
            {
                // use methods like `public T SaveState()`
                var stateObject = methodInfo.Invoke(viewModel, Array.Empty <object>());
                if (stateObject != null)
                {
                    toReturn.Write(stateObject);
                }
            }

            // call the general `public void SaveState(bundle)` method too
            viewModel.SaveState(toReturn);

            return(toReturn);
        }
        public static IMvxBundle SaveStateBundle(this IMvxViewModel viewModel)
        {
            var toReturn = new MvxBundle();
            var methods  = viewModel.GetType()
                           .GetMethods()
                           .Where(m => m.Name == "SaveState")
                           .Where(m => m.ReturnType != typeof(void))
                           .Where(m => !m.GetParameters().Any());

            foreach (var methodInfo in methods)
            {
                // use methods like `public T SaveState()`
                var stateObject = methodInfo.Invoke(viewModel, new object[0]);
                if (stateObject != null)
                {
                    toReturn.Write(stateObject);
                }
            }

            // call the general `public void SaveState(bundle)` method too
            viewModel.SaveState(toReturn);

            return(toReturn);
        }