Note that there are some explanatory texts on larger screens.

plurals
  1. POC# 4.0 Generic report generator from a class
    text
    copied!<p>I am using .NET 4.0, C# 4.0 in Visual Studio 2012 with Code First and Entity Framework.</p> <p>I have a set of classes that I want to use as the basis for various report. The data for the reports is held in an SQL database. An example class is:</p> <pre><code>public class DocumentTrackerChaseReport { public int DocumentTrackerChaseReportID { get; set; } public int CaseID { get; set; } public int DocumentID { get; set; } [Description("Case ID")] public String CaseIdentifier { get; set; } [Description("Document type")] public String DocumentCategory { get; set; } [Description("Contact")] public String ContactName { get; set; } [Description("Phone number")] public String ContactPhoneNumber { get; set; } [Description("email address")] public String ContactEmail { get; set; } public TrackingActionType TrackingActionType { get; set; } } </code></pre> <p>The Description attributes acts both as the headers for the report and also to indicate which properties are to be excluded from the report.</p> <p>I have a method to extract the headers as a string array from <a href="https://stackoverflow.com/questions/16886266/how-to-get-all-descriptions-of-enum-values-with-reflection" title="this">this</a> question</p> <p>I can also generate a method which checks to see if a field/property has a description attribute.</p> <p>The key ingredient I am missing is a straightforward and generic way to generate each line of the report omitting the fields that don't have this attribute. I can iterate through all of the fields using reflection and checking for the attribute for each line of the report but that seems long winded.</p> <p>Is there an elegant solution to this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload