Пример #1
0
        public IModelMapping GetMapping(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            IModelMapping result   = null;
            var           generics = type.GetGenericArguments();

            if (generics.Length > 0)
            {
                Type genericType = type.GetGenericArguments()[0];
                if (genericType != null && typeof(ICollection <>).MakeGenericType(genericType).IsAssignableFrom(type))
                {
                    type = genericType;
                }
            }
            if (modelMappings.ContainsKey(type))
            {
                result = modelMappings[type];
            }
            else if (propertyMappingLists.ContainsKey(type))
            {
                var propertyMappings = propertyMappingLists[type];
                //IList<IModelProperty> modelProperties = new List<IModelProperty>();
                var modelProperties = propertyMappings.Select(mapping =>
                {
                    mapping.GetMapping(mapping.PropertyAttribute, this);    //GetMapping is called when the mapping is first requested, assuming all Binding Modules have been loaded up
                    return(resolver.GetModelProperty(mapping.Property, mapping.PropertyAttribute));
                }).ToList();
                //foreach (var mapping in propertyMappings)
                //{
                //    mapping.GetMapping(mapping.PropertyAttribute, this);
                //    modelProperties.Add(resolver.GetModelProperty(mapping.Property, mapping.PropertyAttribute));
                //}
                result = new ModelMapping(type, modelProperties);
                modelMappings.Add(type, result); //The first time it's asked for, it's loaded into the dictionary permanently and can't change
            }
            return(result);
        }
Пример #2
0
        public void SetPropertyValue <TModel, TProperty>(TModel model, Expression <Func <TModel, TProperty> > propertyLambda) where TModel : IViewModel
        {
            var property = resolver.GetModelProperty(model, propertyLambda);

            SetPropertyValue(model, property);
        }