Beispiel #1
0
 public CommerceEntity Map(object from)
 {
     return(ClassMapper <object, CommerceEntity> .MapIfNotNull(from, () =>
     {
         BaseMapping mapping = GetMapping(from.GetType());
         return (mapping != null) ? mapping.MapFrom(from) : null;
     }));
 }
Beispiel #2
0
 public object Map(CommerceEntity from, Type mappedType)
 {
     return(ClassMapper <CommerceEntity, object> .MapIfNotNull(from, () =>
     {
         BaseMapping baseMapping = GetMapping(mappedType);
         return baseMapping != null ? baseMapping.MapTo(from) : null;
     }));
 }
Beispiel #3
0
        internal BaseMapping GetMapping(Type typeInfo)
        {
            BaseMapping baseMapping = null;

            if (_mappings.ContainsKey(typeInfo.TypeHandle))
            {
                baseMapping = _mappings[typeInfo.TypeHandle];
            }
            else
            {
                var genericMappingType = typeof(Mapping <>);
                var mappingType        = genericMappingType.MakeGenericType(new[] { typeInfo });
                var mapping            = (BaseMapping)Activator.CreateInstance(mappingType);

                if (!String.IsNullOrEmpty(mapping.ModelName))
                {
                    _mappings.Add(typeInfo.TypeHandle, mapping);
                    baseMapping = mapping;
                }
            }

            return(baseMapping);
        }