Exemplo n.º 1
0
 /// <summary>
 /// Builds a <paramref name="componentType"/> for the type <typeparamref name="TValue"/>.
 /// </summary>
 /// <typeparam name="TValue">The type of the value.</typeparam>
 /// <param name="model">The model.</param>
 /// <param name="componentType">The type of the component.</param>
 /// <param name="propertyInfo">The property information.</param>
 /// <param name="builder">The builder.</param>
 /// <param name="currentIndex">The current index in the render tree.</param>
 /// <param name="notificationService">The notification service.</param>
 /// <returns>The updated index in the render tree.</returns>
 protected int BuildField <TValue>(object model, Type componentType, PropertyInfo propertyInfo, RenderTreeBuilder builder, int currentIndex, IChangeNotificationService notificationService)
 {
     builder.OpenComponent(currentIndex++, componentType);
     try
     {
         builder.AddAttribute(currentIndex++, "ValueExpression", model.CreatePropertyExpression <TValue>(propertyInfo));
         builder.AddAttribute(currentIndex++, "Value", propertyInfo.GetValue(model));
         builder.AddAttribute(currentIndex++, "ValueChanged", EventCallback.Factory.Create(this, EventCallback.Factory.Create <TValue>(
                                                                                               this,
                                                                                               value =>
         {
             if (propertyInfo.SetMethod is { })
             {
                 propertyInfo.SetValue(model, value);
                 notificationService.NotifyChange(model, propertyInfo.Name);
             }
         })));