// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Blazor.Components; using Microsoft.AspNetCore.Blazor.RenderTree; using System.Collections.Generic; namespace Microsoft.AspNetCore.Blazor.Test.Helpers { public static class IComponentExtensions { public static void SetParameters( this IComponent component, Dictionary parameters) { component.SetParameters(DictionaryToParameterCollection(parameters)); } private static ParameterCollection DictionaryToParameterCollection( IDictionary parameters) { var builder = new RenderTreeBuilder(new TestRenderer()); builder.OpenComponent(0); foreach (var pair in parameters) { builder.AddAttribute(0, pair.Key, pair.Value); } builder.CloseElement(); return new ParameterCollection(builder.GetFrames().Array, 0); } private abstract class AbstractComponent : IComponent { public abstract void Init(RenderHandle renderHandle); public abstract void SetParameters(ParameterCollection parameters); } } }