/// <summary> /// Maps a node based on the <paramref name="context"/>. /// </summary> /// <param name="context">The context which describes the node mapping.</param> /// <param name="destinationType">The type to map to.</param> /// <returns><c>null</c> if the node does not exist.</returns> internal object Map(NodeMappingContext context, Type destinationType) { if (context == null) { throw new ArgumentNullException("context"); } else if (destinationType == null) { throw new ArgumentNullException("destinationType"); } else if (!NodeMappers.ContainsKey(destinationType)) { throw new MapNotFoundException(destinationType); } string sourceNodeTypeAlias = null; if (_cacheProvider != null && _cacheProvider.ContainsAlias(context.Id)) { sourceNodeTypeAlias = _cacheProvider.GetAlias(context.Id); if (sourceNodeTypeAlias == null) { // Node does not exist return(null); } } if (sourceNodeTypeAlias == null) { var node = context.GetNode(); if (node == null || string.IsNullOrEmpty(node.Name)) { // Node doesn't exist if (_cacheProvider != null) { _cacheProvider.InsertAlias(context.Id, null); } return(null); } if (_cacheProvider != null) { _cacheProvider.InsertAlias(context.Id, node.DocumentTypeAlias); } sourceNodeTypeAlias = node.DocumentTypeAlias; } var nodeMapper = GetMapper(sourceNodeTypeAlias, destinationType); if (nodeMapper == null) { return(null); } return(nodeMapper.MapNode(context)); }