Enumerate properties of ReadOnlyList

Enumerate properties of ReadOnlyList

Old forum URL: forums.lhotka.net/forums/t/6706.aspx


nj609eagle posted on Tuesday, March 31, 2009

I'm trying to work with a sample code to craete a custom ActionResult for our MVC application.  This actionResult will create an Excel File (http://stephenwalther.com/blog/archive/2008/06/16/asp-net-mvc-tip-2-create-a-custom-action-result-that-returns-microsoft-excel-documents.aspx)

Since we're not using Linq to SQL, I want to replace teh dataContext paramters with a CSLA business object.  Probably a ReadOnlyListBase object.  I need to spin through one Item of what the list hold to retrieve the property names to use as column headers.

Any suggestions?

RockfordLhotka replied on Tuesday, March 31, 2009

You'll need to use reflection.

The best thing to do is to use the TypeDescriptor subsystem, which sits on top of basic reflection and adds extra things like telling you whether a property is read-only, etc.

You can google for how to get TypeDescriptor information from your type, or search the CSLA codebase, because I use it in a couple places (like the CslaDataSource control).

Copyright (c) Marimer LLC