|
@*Properties Iterated from 'Order' model*@
@foreach (PropertyInfo propertyInfo in order.GetType().GetProperties())
{
// For String Type Model Properties
if (propertyInfo.PropertyType == typeof(string))
{
@renderComponent(typeof(TextBox));
}
// For Integer Type Model Properties
else if (propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(int?))
{
@renderComponent(typeof(NumericTextBox));
}
// For DateTime Type Model Properties
else if (propertyInfo.PropertyType == typeof(DateTime?) || propertyInfo.PropertyType == typeof(DateTime))
{
@renderComponent(typeof(DatePicker));
}
// For Generic Type Model Properties
else if(propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
{
@renderComponent(typeof(DropDownList));
}
<br>
}
@code {
Order order = new Order();
private RenderFragment renderComponent(Type com) => builder =>
{
builder.OpenComponent(0, com);
builder.CloseComponent();
};
}
|
|
@using System.Reflection
@for (int i = 0; i < rowCount ; i++)
{
<div class="row">
@for ( int j = 0; j < colCount; j++)
{
//For comparing purpose with Columns
int comp = 0;
@foreach (PropertyInfo Prop in order.GetType().GetProperties())
{
if (!ComponentAlreadyPresent.Contains(Prop.Name) && comp < colCount)
{
<Dynamic colCount="@colCount" Prop ="Prop" ></Dynamic>
<br>
ComponentAlreadyPresent.Add(Prop.Name);
comp++;
}
}
break;
}
</div>
}
@code {
Order order = new Order();
List<string> ComponentAlreadyPresent = new List<string>();
// Change value for set the Columns
public int? colCount = 3;
// Change value for set the Rows
public int? rowCount = 2;
}
|
|
@using System.Reflection
@if (Prop.PropertyType == typeof(string))
{
<div class=@colSplitClass>
@renderComponent(typeof(TextBox))
</div>
}
// For Integer Type Model Properties
else if (Prop.PropertyType == typeof(int) || Prop.PropertyType == typeof(int?))
{
<div class=@colSplitClass>
@renderComponent(typeof(NumericTextBox))
</div>
}
// For DateTime Type Model Properties
else if (Prop.PropertyType == typeof(DateTime?) || Prop.PropertyType == typeof(DateTime))
{
<div class=@colSplitClass>
@renderComponent(typeof(DatePicker))
</div>
}
// For Generic Type Model Properties
else if(Prop.PropertyType.IsGenericType && Prop.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
{
<div class=@colSplitClass>
@renderComponent(typeof(DropDownList))
</div>
}
<br>
@code {
Order order = new Order();
List<ColumnSplitClass> col = new List<ColumnSplitClass> {
new ColumnSplitClass() { Columns= 1, ColClass= "col-xs-12 col-sm-12 col-lg-12 col-md-12" },
new ColumnSplitClass() { Columns= 2, ColClass= "col-xs-6 col-sm-6 col-lg-6 col-md-6" },
new ColumnSplitClass() { Columns= 3, ColClass= "col-xs-4 col-sm-4 col-lg-4 col-md-4" },
new ColumnSplitClass() { Columns= 4, ColClass= "col-xs-3 col-sm-3 col-lg-3 col-md-3" },
new ColumnSplitClass() { Columns= 6, ColClass= "col-xs-2 col-sm-2 col-lg-2 col-md-2" },
new ColumnSplitClass() { Columns= 12, ColClass= "col-xs-1 col-sm-1 col-lg-1 col-md-1" },
};
private RenderFragment renderComponent(Type com) => builder =>
{
builder.OpenComponent(0, com);
builder.CloseComponent();
};
public string colSplitClass{ get; set; }
[Parameter]
public int? colCount{ get; set; }
[Parameter]
public PropertyInfo Prop{ get; set; }
protected override void OnInitialized()
{
foreach (ColumnSplitClass item in col)
{
if(item.Columns == colCount)
{
//Assign the Bootstrap column split class based on the columns
this.colSplitClass = item.ColClass;
break;
}
}
}
}
|