//internal static ICollection<IChildMemberConfiguration> sourceToDestinationMemberMappers = new Collection<IChildMemberConfiguration> //{ // // Need to do it fixie way for prefix and postfix to work together + not specify match explicitly // // Have 3 properties for Members, Methods, And External Methods // // Parent goes to all // new MemberConfiguration().AddMember<NameSplitMember>().AddName<PrePostfixName>(_ => _.AddStrings(p => p.Prefixes, "Get")).SetMemberInfo<AllMemberInfo>(), // //new CustomizedSourceToDestinationMemberMapper().MemberNameMatch().ExtensionNameMatch().ExtensionPrefix("Get").MethodPrefix("Get").MethodNameMatch(), //}; //internal static readonly ICollection<IChildMemberConfiguration> def = sourceToDestinationMemberMappers.ToList(); public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IProfileConfiguration options, MemberList memberList) { var sourceTypeInfo = GetTypeInfo(sourceType, options); var destTypeInfo = GetTypeInfo(destinationType, options); var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList); foreach (var destProperty in destTypeInfo.PublicWriteAccessors) { var members = new LinkedList<MemberInfo>(); if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.GetType(), destProperty.Name, members)) { var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi)); var destPropertyAccessor = ReflectionHelper.ToMemberAccessor(destProperty); typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>()); } } if (!TypeExtensions.IsAbstract(destinationType) && TypeExtensions.IsClass(destinationType)) { foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length)) { if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options)) { break; } } } return typeMap; }
public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames) { TypeMap = typeMap; UnmappedPropertyNames = unmappedPropertyNames; }
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration 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(options, sourceTypeInfo, parameter.GetType(), parameter.Name, members); var resolvers = members.Select(mi => ReflectionHelper.ToMemberGetter(mi)); var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve); parameters.Add(param); } typeMap.AddConstructorMap(destCtor, parameters); return true; }
private ResolutionContext(ResolutionContext context, TypeMap memberTypeMap, object sourceValue, object destinationValue, Type sourceType, Type destinationType) : this(context, sourceValue, destinationValue, sourceType, destinationType, memberTypeMap) { }
private ResolutionContext(ResolutionContext context, object sourceValue, TypeMap typeMap, Type sourceType, Type destinationType, int arrayIndex) : this(context, sourceValue, null, sourceType, destinationType, typeMap) { ArrayIndex = arrayIndex; }
public ResolutionContext(TypeMap typeMap, object source, Type sourceType, Type destinationType, MappingOperationOptions options, IMappingEngine engine) : this(typeMap, source, null, sourceType, destinationType, options, engine) { }
public ResolutionContext CreateElementContext(TypeMap elementTypeMap, object item, Type sourceElementType, Type destinationElementType, int arrayIndex) { return(new ResolutionContext(this, item, elementTypeMap, sourceElementType, destinationElementType, arrayIndex)); }
public ResolutionContext CreateTypeContext(TypeMap memberTypeMap, object sourceValue, object destinationValue, Type sourceType, Type destinationType) { return(new ResolutionContext(this, memberTypeMap, sourceValue, destinationValue, sourceType, destinationType)); }
public TypeMapCreatedEventArgs(TypeMap typeMap) { TypeMap = typeMap; }