public TDestination Map(IPublishedContent node) { if (node == null || string.IsNullOrEmpty(node.Name)) { return(null); } var context = new NodeMappingContext(node, _paths.ToArray(), null); return((TDestination)_engine.Map( context, typeof(TDestination) )); }
/// <summary> /// Maps an Umbraco <c>Node</c> to a new instance of <typeparamref name="TDestination"/>. /// </summary> /// <typeparam name="TDestination">The type to map to.</typeparam> /// <param name="sourceNode">The <c>Node</c> to map from.</param> /// <param name="includeRelationships">Whether to load relationships.</param> /// <returns> /// A new instance of <typeparamref name="TDestination"/>, or <c>null</c> if /// <paramref name="sourceNode"/> is <c>null</c> or does not map to /// <typeparamref name="TDestination"/>. /// </returns> /// <exception cref="MapNotFoundException"> /// If a map for <typeparamref name="TDestination"/> has not /// been created with <see cref="CreateMap()" />. /// </exception> public static TDestination Map <TDestination>(IPublishedContent sourceNode, bool includeRelationships = true) where TDestination : class, new() { if (sourceNode == null || string.IsNullOrEmpty(sourceNode.Name)) { return(null); } var paths = includeRelationships ? null // all : new string[0]; // none var context = new NodeMappingContext(sourceNode, paths, null); return((TDestination)_engine.Map(context, typeof(TDestination))); }