コード例 #1
0
        /// <summary>
        /// Finds all components of type <typeparamref name="TComponent"/> in the render tree of
        /// this <see cref="IRenderedFragment"/>.
        /// </summary>
        /// <typeparam name="TComponent">Type of components to find.</typeparam>
        /// <returns>The <see cref="IRenderedComponent{T}"/>s</returns>
        public static IReadOnlyList <IRenderedComponent <TComponent> > FindComponents <TComponent>(this IRenderedFragment renderedFragment) where TComponent : IComponent
        {
            if (renderedFragment is null)
            {
                throw new ArgumentNullException(nameof(renderedFragment));
            }

            var renderer   = renderedFragment.Services.GetRequiredService <ITestRenderer>();
            var components = renderer.FindComponents <TComponent>(renderedFragment.ComponentId);
            var result     = components.Count == 0 ? Array.Empty <IRenderedComponent <TComponent> >() : new IRenderedComponent <TComponent> [components.Count];

            for (int i = 0; i < components.Count; i++)
            {
                result[i] = new RenderedComponent <TComponent>(renderedFragment.Services, components[i].ComponentId, components[i].Component);
            }

            return(result);
        }
コード例 #2
0
        /// <inheritdoc/>
        public virtual IRenderedComponent <TComponent> RenderComponent <TComponent>(params ComponentParameter[] parameters) where TComponent : class, IComponent
        {
            var result = new RenderedComponent <TComponent>(this, parameters);

            return(result);
        }