/// <summary> /// Creates and returns a type map definition. /// </summary> /// <param name="key">The type map definition key.</param> /// <returns>The generated type map definition.</returns> private static TypeMapDefinition CreateDefinition(TypeMapDefinitionKey key) { TypeMapDefinition definition = new TypeMapDefinition(key.SourceType, key.DestinationType); _storedDefinitions.Add(key, definition); return(definition); }
/// <summary> /// Creates and caches a type map definition. /// </summary> /// <typeparam name="S">The type to use for the source.</typeparam> /// <typeparam name="T">The type to use for the definition.</typeparam> public static void CreateDefinition <S, T>() { Type sourceType = typeof(S); Type destinationType = typeof(T); TypeMapDefinitionKey key = new TypeMapDefinitionKey(sourceType, destinationType); if (_storedDefinitions.ContainsKey(key) == false) { CreateDefinition(key); } }
/// <summary> /// Performs a property mapping of one object to the next. /// </summary> /// <typeparam name="S">The type to use for the source.</typeparam> /// <typeparam name="T">The type to use for the definition.</typeparam> /// <param name="source">The source object to map from.</param> /// <param name="destination">The destination object to map to.</param> public static void Map <S, T>(S source, T destination) { TypeMapDefinition definition; Type sourceType = typeof(S); Type destinationType = typeof(T); TypeMapDefinitionKey key = new TypeMapDefinitionKey(sourceType, destinationType); if (_storedDefinitions.TryGetValue(key, out definition) == false) { definition = CreateDefinition(key); } definition.PerformMap(source, destination); }