internal static void MapModelNode(
     IModelNode genericModelNode,
     LayoutItemNode genericLayoutItemNode
     )
 {
     if (genericLayoutItemNode.Index is not null)
     {
         genericModelNode.Index =
             genericLayoutItemNode.Index ?? genericModelNode.Index;
     }
 }
        internal static void MapModelViewLayoutElement(
            IModelViewLayoutElement modelModelViewLayoutElement,
            LayoutItemNode layoutViewItemNode
            )
        {
            if (layoutViewItemNode.Id is not null)
            {
                modelModelViewLayoutElement.Id =
                    layoutViewItemNode.Id ?? modelModelViewLayoutElement.Id;
            }

            if (layoutViewItemNode.RelativeSize is not null)
            {
                modelModelViewLayoutElement.RelativeSize =
                    layoutViewItemNode.RelativeSize ?? modelModelViewLayoutElement.RelativeSize;
            }
        }
            static IEnumerable <TItem> VisitNodes <TItem>(LayoutItemNode node)
                where TItem : LayoutItemNode
            {
                if (node is TItem targetNode)
                {
                    yield return(targetNode);
                }

                if (node is IEnumerable <LayoutItemNode> items)
                {
                    foreach (var item in items)
                    {
                        foreach (var nestedItem in VisitNodes <TItem>(item))
                        {
                            yield return(nestedItem);
                        }
                    }
                }
            }
 IModelViewLayoutElement?IModelViewLayoutElementFactory.CreateViewLayoutElement(IModelNode parentNode, LayoutItemNode layoutItemNode)
 {
     if (layoutItemNode is TLayoutItemNode tLayoutItemNode)
     {
         return(CreateViewLayoutElement(parentNode, tLayoutItemNode));
     }
     return(null);
 }
 bool IModelViewLayoutElementFactory.Handles(LayoutItemNode layoutItemNode) => layoutItemNode is TLayoutItemNode;
            public IModelViewLayoutElement?CreateViewLayoutElement(IModelNode parentNode, LayoutItemNode layoutItemNode)
            {
                IModelViewLayoutElementFactory?FindFactory(Type?type)
                {
                    if (type is null)
                    {
                        return(null);
                    }
                    if (modelViewLayoutElementFactories.ContainsKey(type))
                    {
                        return(modelViewLayoutElementFactories[type].Value);
                    }
                    return(FindFactory(type.GetBaseType()));
                }

                var builder = FindFactory(layoutItemNode.GetType());

                if (builder is not null)
                {
                    if (builder.Handles(layoutItemNode))
                    {
                        return(builder.CreateViewLayoutElement(parentNode, layoutItemNode));
                    }
                }

                return(null);
            }