private void InjectDictionary(IDictionary dictionary, IDictionary target, Type targetType) { foreach (DictionaryEntry item in dictionary) { // Gets the value type. var itemValueType = targetType.GetGenericArguments().ElementAt(1); // If the list is for primitive values, just add the value to the list if (FWReflectionHelper.IsPrimitive(itemValueType)) { target.Add(item.Key, item.Value); } else { if (item.Value != null) { // If the list is for complex types, try to map each item. var newItem = InjectFrom(itemValueType, item.Value); target.Add(item.Key, newItem); } else { target.Add(item.Key, null); } } } }
private void SetValue(object source, object target, MemberInfo sourceMember, MemberInfo targetMember) { var targetType = targetMember.GetMemberType(); if (!FWReflectionHelper.IsPrimitive(targetType)) { var complexObject = sourceMember.GetValue(source); if (complexObject != null) { // Gets the target object property value var targetMemberValue = targetMember.GetValue(target); // Gets the property type or, if it is an interface, from the source object type var type = (!targetType.IsInterface) ? targetType : complexObject.GetType(); if (targetMemberValue == null) { targetMemberValue = Activator.CreateInstance(type); } targetMemberValue = InjectFrom(type, complexObject); targetMember.SetValue(target, targetMemberValue); } } else { var val = sourceMember.GetValue(source); // Checks to see if there are any maps for the primitive. val = Omu.ValueInjecter.Mapper.Instance.MapPrimitive(targetType, val); targetMember.SetValue(target, val); } }
/// <summary> /// Adds a property to the model. /// </summary> /// <param name="prop">The property PropertyInfo.</param> /// <param name="model">The model object reference.</param> private void Databind(PropertyInfo prop, object model) { if (FWReflectionHelper.IsPrimitive(prop.PropertyType)) { BindPrimitive(prop, model); } else if (FWReflectionHelper.IsCollection(prop.PropertyType)) { BindCollection(prop, model); } }