internal Mapper(MapDefinition[] mapDefinitions) { int mapDefinitionsCount = mapDefinitions.Length; this._mapTable = new MapTable(ref mapDefinitionsCount); for (int i = 0; i < mapDefinitionsCount; i++) { MapDefinition mapDefinition = mapDefinitions[i]; string hash = this._mapTable.CreateIndex(mapDefinition.TargetType, mapDefinition.SourceType); MapSpecification[] mapSpecifications = mapDefinition.Specifications.ToArray <MapSpecification>(); Map map = new Map(hash, mapSpecifications); this._mapTable.AddMap(ref i, map); } }
/// <summary> /// This method allows you to define a map with your specifications /// </summary> /// <typeparam name="TTargetType">The target type is what you want to be mapped.</typeparam> /// <typeparam name="TSourceType">The source type containing the source of data in the mapping.</typeparam> /// <param name="specifications"><see cref="IMapSpecificationsDefinition{TTargetType, TSourceType}"/></param> /// <returns>Returns MapperBuilder instance for you can define again another type couple.</returns> public IMapperBuilder DefineMapFor <TTargetType, TSourceType>(Action <IMapSpecificationsDefinition <TTargetType, TSourceType> > specifications) { Type targetType = typeof(TTargetType); Type sourceType = typeof(TSourceType); List <MapSpecification> mapSpecifications = this.CreateDefaultAssignmentSpecifications(targetType, sourceType); if (specifications != null) { this.HandleUserDefinedSpecifications(specifications, mapSpecifications); } MapDefinition mapDefinition = new MapDefinition(targetType, sourceType, mapSpecifications); this._definitions.Add(mapDefinition); return(this); }
/// <summary> /// /// </summary> private void DefineUndefinedReverseMaps() { List <MapDefinition> reverseMapDefinitionList = new List <MapDefinition>(); int definedMapCount = this._definitions.Count; for (int i = 0; i < definedMapCount; i++) { MapDefinition mapDefinition = this._definitions[i]; MapDefinition reverseMapDefinition = this._definitions.Find(definition => definition.TargetType == mapDefinition.SourceType && definition.SourceType == mapDefinition.TargetType ); if (reverseMapDefinition == null) { List <MapSpecification> defaultSpecificationsOfReverseMap = this.CreateDefaultAssignmentSpecifications(mapDefinition.SourceType, mapDefinition.TargetType); reverseMapDefinition = new MapDefinition(mapDefinition.SourceType, mapDefinition.TargetType, defaultSpecificationsOfReverseMap); reverseMapDefinitionList.Add(reverseMapDefinition); } } this._definitions.AddRange(reverseMapDefinitionList); }