Exemple #1
0
        public void Ctor_InitializesProperties(object value, PropertyInfoModel propertyInfo)
        {
            var navigationParameterModel = new NavigationParameterModel(value, propertyInfo);

            Assert.Equal(value, navigationParameterModel.Value);
            Assert.Equal(propertyInfo, navigationParameterModel.PropertyInfo);
        }
        /// <summary>
        ///     Creates and adds navigation parameter for the specified property using reflection.
        /// </summary>
        /// <typeparam name="TValue">Type of parameter value.</typeparam>
        /// <param name="propertyExpression">Target property.</param>
        /// <param name="value">Value to set.</param>
        /// <returns>Self.</returns>
        protected FluentNavigatorBase <TViewModel> ApplyParameter <TValue>(
            Expression <Func <TViewModel, TValue> > propertyExpression,
            TValue value)
        {
            var propertyInfo = (PropertyInfo)propertyExpression.GetMemberInfo();
            var parameter    = new NavigationParameterModel(value, new PropertyInfoModel(propertyInfo));

            Parameters.Add(parameter);

            return(this);
        }
Exemple #3
0
        private static void SetValueToProperty(ViewModelBase viewModel, NavigationParameterModel parameter)
        {
            var property = parameter.PropertyInfo.ToPropertyInfo();

            object?GetValue(object?value)
            {
                if (value == null)
                {
                    return(null);
                }

                if (property.PropertyType.IsEnum)
                {
                    return(Enum.ToObject(property.PropertyType, value));
                }

                return(((JObject)value).ToObject(property.PropertyType));
            }

            property.SetValue(viewModel, GetValue(parameter.Value), null);
        }