예제 #1
0
        /// <summary>
        /// Render the component
        /// </summary>
        /// <param name="builder"></param>
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            var context = this.DataContext;

            if (context == null)
            {
                return;
            }

            //TODO add cache !!

            var componentType = ViewModelAttribute.FindTypeByAttributeType <BaseBlazorComponent>(DataContext.GetType());

            // create an instance of this component
            builder.OpenComponent(0, componentType);

            // set the DataContext attribute
            builder.AddAttribute(1, nameof(DataContext), DataContext);

            // close
            builder.CloseComponent();
        }
예제 #2
0
 public void Initialize(Assembly assembly)
 {
     Initialize(assembly,
                ViewModelAttribute.GetAttributedTypes(assembly)
                .ToDictionary(x => x.Type, x => x.Attribute.ViewModel));
 }