public static void RenderChildren(RenderTreeBuilder builder, int index, object dataContext, string fieldIdentifier) { // the builder position is between the builder.OpenComponent() and builder.CloseComponent() // This means that the component of InputSelect is added en stil open for changes. // We can create a new RenderFragment and set the ChildContent attribute of the InputSelect component builder.AddAttribute(index + 1, nameof(ChildContent), new RenderFragment(_builder => { // check if the type of the propery is an Enum if (typeof(TValue).IsEnum) { // when type is a enum present them as an <option> element // by leveraging the component InputSelectOption var values = typeof(TValue).GetEnumValues(); foreach (var val in values) { var value = VxSelectItem.ToSelectItem(val as Enum); // Open the InputSelectOption component _builder.OpenComponent(0, TypeOfChildToRender); // Set the value of the enum as a value and key parameter _builder.AddAttribute(1, nameof(InputSelectOption <string> .Value), value.Label); _builder.AddAttribute(2, nameof(InputSelectOption <string> .Key), value.Key); // Close the component _builder.CloseComponent(); } } })); }
private static void Enum(RenderTreeBuilder _builder, object dataContext) { // when type is a enum present them as an <option> element // by leveraging the component InputSelectOption var values = typeof(TValue).GetEnumValues(); foreach (var val in values) { var value = VxSelectItem.ToSelectItem(val as Enum); // Open the InputSelectOption component _builder.OpenComponent(0, TypeOfChildToRender); // Set the value of the enum as a value and key parameter _builder.AddAttribute(1, nameof(InputSelectOption <string> .Value), value.Label); _builder.AddAttribute(2, nameof(InputSelectOption <string> .Key), value.Key); // Close the component _builder.CloseComponent(); } }
private static void VxLookup(RenderTreeBuilder _builder, object dataContext, string fieldIdentifier) { // when type is a enum present them as an <option> element // by leveraging the component InputSelectOption var leads = dataContext.GetType().GetProperty(fieldIdentifier).GetValue(dataContext); var values = (List <VxLookup>)leads.GetType().GetProperty("List").GetValue(leads); //if (values.Count > 0) foreach (var val in values) { var value = new VxSelectItem(val.Id, val.Value); // Open the InputSelectOption component _builder.OpenComponent(0, TypeOfChildToRender); // Set the value of the enum as a value and key parameter _builder.AddAttribute(1, nameof(InputSelectOption <string> .Value), value.Label); _builder.AddAttribute(2, nameof(InputSelectOption <string> .Key), value.Key); // Close the component _builder.CloseComponent(); } }