Пример #1
0
        /// <summary>
        /// Creates new instance of <see cref="UITree"/> by copying from the specified source
        /// </summary>
        /// <param name="sourceTree">source tree</param>
        public UITree(IUITree sourceTree)
        {
            if (sourceTree == null)
            {
                throw new MemoryPointerIsNullException("sourceTree");
            }

            this.roots = new List <UITreeNode>();
            Map(sourceTree, this, SimpleMap);
        }
Пример #2
0
        /// <summary>
        /// Creates new instance of <see cref="UITree"/> by copying from the specified source and using entity mappings
        /// </summary>
        /// <typeparam name="TSourceEntity">entity type in current tree</typeparam>
        /// <typeparam name="TDestinationEntity">entity type in mapped tree</typeparam>
        /// <param name="sourceTree">source tree</param>
        /// <param name="entityMappingFunction">entity mapping function</param>
        /// <returns>new tree instance with entity nodes of new type</returns>
        public static UITree Create <TSourceEntity, TDestinationEntity>(IUITree sourceTree, Func <TSourceEntity, TDestinationEntity> entityMappingFunction)
        {
            if (sourceTree == null)
            {
                throw new MemoryPointerIsNullException("sourceTree");
            }

            if (entityMappingFunction == null)
            {
                throw new MemoryPointerIsNullException("entityMappingFunction");
            }

            var tree = new UITree();

            MapEntityNodes(sourceTree, tree, entityMappingFunction);
            return(tree);
        }
Пример #3
0
 private static void MapEntityNodes <TSourceEntity, TDestinationEntity>(
     IUITree sourceTree, UITree destinationTree, Func <TSourceEntity, TDestinationEntity> entityMappingFunction)
 {
     destinationTree.Roots.AddRange(MapWithConvertEntityNodes(sourceTree.GetRoots(), entityMappingFunction));
 }
Пример #4
0
 private static void Map(IUITree sourceTree, UITree destinationTree, Func <List <IUITreeNode>, List <UITreeNode> > mappingFunction)
 {
     destinationTree.Roots.AddRange(mappingFunction(sourceTree.GetRoots()));
 }