예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelToModelMapping"/> class.
        /// </summary>
        /// <param name="viewModelProperty">The view model property.</param>
        /// <param name="modelProperty">The model property.</param>
        /// <param name="valueProperty">The value property.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="converterType">Converter type</param>
        /// <param name="additionalConstructorArgs">Constructor args</param>
        /// <param name="additionalPropertiesToWatch"></param>
        /// <exception cref="ArgumentException">The <paramref name="viewModelProperty"/> is <c>null</c> or whitespace.</exception>
        public ViewModelToModelMapping(string viewModelProperty, string modelProperty, string valueProperty, ViewModelToModelMode mode, Type converterType, object[] additionalConstructorArgs, string[] additionalPropertiesToWatch)
        {
            Argument.IsNotNullOrWhitespace("viewModelProperty", viewModelProperty);

            ViewModelProperty = viewModelProperty;
            ModelProperty     = modelProperty;
            Mode          = mode;
            ConverterType = converterType;

            var propertiesLength = 1 + (additionalPropertiesToWatch == null ? 0 : additionalPropertiesToWatch.Length);

            ValueProperties    = new string[propertiesLength];;
            ValueProperties[0] = valueProperty;

            if (propertiesLength > 1)
            {
                additionalPropertiesToWatch.CopyTo(ValueProperties, 1);
            }

            var argsLength = 1 + (additionalConstructorArgs == null ? 0 : additionalConstructorArgs.Length);
            var args       = new object[argsLength];

            args[0] = ValueProperties;

            if (argsLength > 1)
            {
                additionalConstructorArgs.CopyTo(args, 1);
            }

            Converter = (IViewModelToModelConverter)this.GetTypeFactory().CreateInstanceWithParameters(ConverterType, args);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelToModelMapping"/> class.
        /// </summary>
        /// <param name="viewModelProperty">The view model property.</param>
        /// <param name="modelProperty">The model property.</param>
        /// <param name="valueProperty">The value property.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="converterType">Converter type</param>
        /// <param name="additionalConstructorArgs">Constructor args</param>
        /// <param name="additionalPropertiesToWatch"></param>
        /// <exception cref="ArgumentException">The <paramref name="viewModelProperty"/> is <c>null</c> or whitespace.</exception>
        public ViewModelToModelMapping(string viewModelProperty, string modelProperty, string valueProperty, ViewModelToModelMode mode, Type converterType, object[] additionalConstructorArgs, string[] additionalPropertiesToWatch)
        {
            Argument.IsNotNullOrWhitespace("viewModelProperty", viewModelProperty);

            ViewModelProperty = viewModelProperty;
            ModelProperty = modelProperty;
            Mode = mode;
            ConverterType = converterType;

            var propertiesLength = 1 + (additionalPropertiesToWatch == null ? 0 : additionalPropertiesToWatch.Length);
            ValueProperties = new string[propertiesLength]; ;
            ValueProperties[0] = valueProperty;

            if (propertiesLength > 1)
                additionalPropertiesToWatch.CopyTo(ValueProperties, 1);

            var argsLength = 1 + (additionalConstructorArgs == null ? 0 : additionalConstructorArgs.Length);
            var args = new object[argsLength];
            args[0] = ValueProperties;

            if (argsLength > 1)
                additionalConstructorArgs.CopyTo(args, 1);

            Converter = (IViewModelToModelConverter)this.GetTypeFactory().CreateInstanceWithParameters(ConverterType, args);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelToModelMapping"/> class.
        /// </summary>
        /// <param name="viewModelProperty">The view model property.</param>
        /// <param name="modelProperty">The model property.</param>
        /// <param name="valueProperty">The value property.</param>
        /// <param name="mode">The mode.</param>
        /// <exception cref="ArgumentException">The <paramref name="viewModelProperty"/> is <c>null</c> or whitespace.</exception>
        public ViewModelToModelMapping(string viewModelProperty, string modelProperty, string valueProperty, ViewModelToModelMode mode)
        {
            Argument.IsNotNullOrWhitespace("viewModelProperty", viewModelProperty);

            ViewModelProperty = viewModelProperty;
            ModelProperty     = modelProperty;
            ValueProperty     = valueProperty;
            Mode = mode;
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelToModelMapping"/> class.
        /// </summary>
        /// <param name="viewModelProperty">The view model property.</param>
        /// <param name="modelProperty">The model property.</param>
        /// <param name="valueProperty">The value property.</param>
        /// <param name="mode">The mode.</param>
        /// <exception cref="ArgumentException">The <paramref name="viewModelProperty"/> is <c>null</c> or whitespace.</exception>
        public ViewModelToModelMapping(string viewModelProperty, string modelProperty, string valueProperty, ViewModelToModelMode mode)
        {
            Argument.IsNotNullOrWhitespace("viewModelProperty", viewModelProperty);

            ViewModelProperty = viewModelProperty;
            ModelProperty = modelProperty;
            ValueProperty = valueProperty;
            Mode = mode;
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelToModelMapping"/> class.
        /// </summary>
        /// <param name="viewModelProperty">The view model property.</param>
        /// <param name="viewModelPropertyType">The view model property type.</param>
        /// <param name="modelProperty">The model property.</param>
        /// <param name="modelPropertyType">The model property type.</param>
        /// <param name="valueProperty">The value property.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="converterType">Converter type</param>
        /// <param name="additionalConstructorArgs">Constructor args</param>
        /// <param name="additionalPropertiesToWatch"></param>
        /// <exception cref="ArgumentException">The <paramref name="viewModelProperty"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentException">The <paramref name="modelPropertyType"/> is <c>null</c> or whitespace.</exception>
        public ViewModelToModelMapping(string viewModelProperty, Type viewModelPropertyType, string modelProperty, Type modelPropertyType, string valueProperty,
                                       ViewModelToModelMode mode, Type converterType, object[] additionalConstructorArgs, string[] additionalPropertiesToWatch)
        {
            Argument.IsNotNullOrWhitespace("viewModelProperty", viewModelProperty);
            Argument.IsNotNull("viewModelPropertyType", viewModelPropertyType);

            IgnoredProperties     = new HashSet <string>();
            ViewModelProperty     = viewModelProperty;
            ViewModelPropertyType = viewModelPropertyType;
            ModelProperty         = modelProperty;
            ModelPropertyType     = modelPropertyType;
            Mode          = mode;
            ConverterType = converterType;

            var propertiesLength = 1 + (additionalPropertiesToWatch is null ? 0 : additionalPropertiesToWatch.Length);

            ValueProperties    = new string[propertiesLength];;
            ValueProperties[0] = valueProperty;

            if (propertiesLength > 1)
            {
                additionalPropertiesToWatch?.CopyTo(ValueProperties, 1);
            }

            var argsLength = 1 + (additionalConstructorArgs is null ? 0 : additionalConstructorArgs.Length);
            var args       = new object[argsLength];

            args[0] = ValueProperties;

            if (argsLength > 1)
            {
                additionalConstructorArgs?.CopyTo(args, 1);
            }

            var typeFactory = this.GetTypeFactory();
            var converter   = (IViewModelToModelConverter)typeFactory.CreateInstanceWithParameters(ConverterType, args);

            if (converter is null)
            {
                throw Log.ErrorAndCreateException <InvalidOperationException>($"Failed to create converter '{ConverterType}'");
            }

            Converter = converter;
        }