private void ValidateViewModelToModelMappings()
{
foreach (var viewModelToModelMapping in _viewModelToModelMap)
{
var mapping = viewModelToModelMapping.Value;
if (!IsModelRegistered(mapping.ModelProperty))
{
throw Log.ErrorAndCreateException(msg => new ModelNotRegisteredException(mapping.ModelProperty, mapping.ViewModelProperty),
"There is no model '{0}' registered with the model attribute, so the ViewModelToModel attribute on property '{1}' is invalid",
mapping.ModelProperty, mapping.ViewModelProperty);
}
var viewModelPropertyType = GetPropertyData(mapping.ViewModelProperty).Type;
var modelPropertyType = GetPropertyData(mapping.ModelProperty).Type;
var modelPropertyPropertyTypes = new List<Type>(mapping.ValueProperties.Length);
foreach (var valueProperty in mapping.ValueProperties)
{
var modelPropertyPropertyInfo = modelPropertyType.GetPropertyEx(valueProperty);
if (modelPropertyPropertyInfo == null)
{
Log.Warning("Mapped viewmodel property '{0}' to model property '{1}' is invalid because property '{1}' is not found on the model '{2}'.\n\n" +
"If the property is defined in a sub-interface, reflection does not return it as a valid property. If this is the case, you can safely ignore this warning",
mapping.ViewModelProperty, valueProperty, mapping.ModelProperty);
}
else
{
modelPropertyPropertyTypes.Add(modelPropertyPropertyInfo.PropertyType);
}
}
if (!mapping.Converter.CanConvert(modelPropertyPropertyTypes.ToArray(), viewModelPropertyType, GetType()))
{
Log.Warning("Property '{0}' mapped on model properties '{1}' cannot be converted via given converter '{2}'",
mapping.ViewModelProperty, string.Join(", ", mapping.ValueProperties), mapping.ConverterType);
}
}
}