public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options, MemberList memberList) { var sourceTypeInfo = GetTypeInfo(sourceType, options); var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]); var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList); foreach (var destProperty in destTypeInfo.PublicWriteAccessors) { var members = new LinkedList<MemberInfo>(); if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options)) { var resolvers = members.Select(mi => mi.ToMemberGetter()); var destPropertyAccessor = destProperty.ToMemberAccessor(); typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>()); } } if (!destinationType.IsAbstract() && destinationType.IsClass()) { foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length)) { if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options)) { break; } } } return typeMap; }
public TypeMapCreatedEventArgs(TypeMap typeMap) { TypeMap = typeMap; }
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo, IMappingOptions options) { var parameters = new List<ConstructorParameterMap>(); var ctorParameters = destCtor.GetParameters(); if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled) return false; foreach (var parameter in ctorParameters) { var members = new LinkedList<MemberInfo>(); var canResolve = MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options); var resolvers = members.Select(mi => mi.ToMemberGetter()); var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve); parameters.Add(param); } typeMap.AddConstructorMap(destCtor, parameters); return true; }
private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap) { foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped())) { var conventionPropertyMap = GetPropertyMaps() .SingleOrDefault(m => m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name); if (conventionPropertyMap != null && inheritedMappedProperty.HasCustomValueResolver && !conventionPropertyMap.HasCustomValueResolver) { conventionPropertyMap.AssignCustomValueResolver( inheritedMappedProperty.GetSourceValueResolvers().First()); conventionPropertyMap.AssignCustomExpression(inheritedMappedProperty.CustomExpression); } else if (conventionPropertyMap == null) { var propertyMap = new PropertyMap(inheritedMappedProperty); AddInheritedPropertyMap(propertyMap); } } //Include BeforeMap if (inheritedTypeMap.BeforeMap != null) AddBeforeMapAction(inheritedTypeMap.BeforeMap); //Include AfterMap if (inheritedTypeMap.AfterMap != null) AddAfterMapAction(inheritedTypeMap.AfterMap); }
public void InheritTypes(TypeMap inheritedTypeMap) { foreach (var includedDerivedType in inheritedTypeMap._includedDerivedTypes .Where(includedDerivedType => !_includedDerivedTypes.Contains(includedDerivedType))) { _includedDerivedTypes.Add(includedDerivedType); } }
public bool Equals(TypeMap other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other._sourceType, _sourceType) && Equals(other._destinationType, _destinationType); }
public void ApplyInheritedMap(TypeMap inheritedTypeMap) { _inheritedTypeMaps.Add(inheritedTypeMap); }
public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames) { TypeMap = typeMap; UnmappedPropertyNames = unmappedPropertyNames; }