This is a migrated thread and some comments may be shown as answers.
StackOverflowException dynamically building a Grid
1 Answer 32 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edwin
Top achievements
Rank 1
Edwin asked on 25 Jun 2012, 11:58 AM

Using dynamic method invocations to create a Grid, I get a StackOverflowException:

Working example (no dynamic invocations):

<%
    Telerik.Web.Mvc.UI.ViewComponentFactory tVcf = Html.Telerik();
    tVcf.Grid<Applicatie>((IEnumerable<Applicatie>)ViewData["Applicaties"]).Name("test").Render();
%>

Crashing example (identical, but using dynamic invocation; throws StackOverflowException):

<%
    Telerik.Web.Mvc.UI.ViewComponentFactory tVcf2 = Html.Telerik();
    object oGrid = tVcf2.Grid<Applicatie>((IEnumerable<Applicatie>)ViewData["Applicaties"]);
    dynamic dGrid = oGrid;
    dynamic dGrid2 = dGrid.Name("test2");
    dGrid2.Render();
     %>

The IEnumerable is a EntityFramework IQueryable to a database table containing a single record.

The above is just a simplified example. What I really want to accomplish is the runtime creation of a Grid<T>(IEnumerable<T>), where the IEnumerable in reality is an IQueryable, so I get excellent performance:

Type runtimeType = model.GetType(); // The runtime model type

Type ienumType = runtimeType.GetIEnumerableType(); // The runtime model's T, when IEnumerable<T>

// Html.Telerik():

telerik.UI.ViewComponentFactory tVcf = telerik.UI.HtmlHelperExtension.Telerik(hh);
 
// Html.Telerik().Grid<T>(IEnumerable<T> model):
MethodInfo gridUngeneric = typeof(telerik.UI.ViewComponentFactory)
    .GetMethods().Where(x => x.Name == "Grid"
                             && x.IsGenericMethod
                             && x.GetParameters().Count() == 1
                             && x.GetParameters()[0].ParameterType.IsGenericType
                             && x.GetParameters()[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable<>)
                       ).Single();
MethodInfo gridGeneric = gridUngeneric.MakeGenericMethod(ienumType);            
object objgrid = gridGeneric.Invoke(tVcf, new object[] { model });
dynamic grid = objgrid;

// The rest....
System.Linq.Expressions.Expression<Func<telerik.UI.Fluent.GridResizingSettingsBuilder, telerik.UI.Fluent.GridResizingSettingsBuilder>> resizable = res => res.Columns(true);
System.Linq.Expressions.Expression<Func<telerik.UI.Fluent.GridReorderingSettingsBuilder, telerik.UI.Fluent.GridReorderingSettingsBuilder>> reorderable = reo => reo.Columns(true);

grid
    .Name("listing-")//+System.Guid.NewGuid().ToString("X"))
    .Sortable()
    .Filterable()
    .Groupable()
    .Pageable()
    .Resizable(resizable)
    .Reorderable(reorderable)
    .ColumnContextMenu()
    .Render();

I already filled this issue as a bug, but I want to know if anybody has a smart solution to get what I want without hitting the "bug".

Please note that the Model is of type object, but has a runtime type of IQueryable<T>.

I am very eager to see if anyone has a smart solution...

Kind regards,

   Edwin.

Version info: VS2010 + Telerik Extensions for ASP.NET MVC Q1 2012, MVC3 binaries, version 2012.1.214.340

1 Answer, 1 is accepted

Sort by
0
Edwin
Top achievements
Rank 1
answered on 25 Jun 2012, 09:20 PM
Typo corrected...
Tags
Grid
Asked by
Edwin
Top achievements
Rank 1
Answers by
Edwin
Top achievements
Rank 1
Share this question
or