Let's say I have a List of WidgetSetting containing values of different types, like bool, int and string:
public class WidgetSetting {
public string name { get; set; }
public string property { get; set; }
public object value { get; set; }
public Type type { get; set; }
}
Below there are two settings examples:
new WidgetSetting() {
name = Front.Language.Service.GetSetting(EN_Setting.Widget_AccessList_Count),
property = nameof(count),
value = 100,
type = typeof(int)
},
new WidgetSetting() {
name = Front.Language.Service.GetSetting(EN_Setting.Widget_AccessList_Pagination),
property = nameof(pagination),
value = true,
type = typeof(bool)
}
When binding the value to a CheckBox and to a Numeric, it works as expected:
However the TextBox throws the following compilation error:
This is because the binded value is expected to be a string:
@inherits FormComponent<string>
In Numeric and CheckBox a generic value is expected:
@typeparam TValue
@inherits FormComponent<TValue>
Which later on is manipulated like so:
Value = (TValue)ConvertType.ChangeType(newValue, typeof(TValue));
...
TValue newValue;
BindConverter.TryConvertTo<TValue>($"{args.Value}", System.Globalization.CultureInfo.CurrentCulture, out newValue);
...
await JSRuntime.InvokeAsync<string>("Radzen.setInputValue", input, Value);
It seems that this can also work in the TextBox component, and probably in every other component.