Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to implement a generic scheduler object in C# 4 which will output a table in HTML. Basic aim is to show some object along with various attributes, and whether it was doing something in a given time period.

The scheduler will output a table displaying the headers:

Detail Field 1 ....N| Date1.........N

I want to initialise the table with a start date and an end date to create the date range (ideally could also do other time periods e.g. hours but that isn't vital). I then want to provide a generic object which will have associated events.

Where an object has events within the period I want a table cell to be marked

E.g.

Name Height Weight 1/1/2011 2/1/2011 3/1/20011...... 31/1/2011
Ben  5.11    75       X        X                       X
Bill 5.7     83                X        X

So I created scheduler with Start Date=1/1/2011 and end date 31/1/2011

I'd like to give it my person object (already sorted) and tell it which fields I want displayed (Name, Height, Weight)

Each person has events which have a start date and end date. Some events will start and end outwith but they should still be shown on the relevant date etc.

Ideally I'd like to have been able to provide it with say a class booking object as well. So I'm trying to keep it generic.

I have seen Javasript implementations etc of similar.

What would a good data structure be for this? Any thoughts on techniques I could use to make it generic. I am not great with generics so any tips appreciated.

share|improve this question
    
with generics you still need a base class or interface to make it typesafe. You can use Reflection to get the Properties at runtime, but this is slower and throws in runtime only –  Firo Dec 12 '11 at 13:28
    
Yeah I was expecting the base class of the data structure to have some sort of structure holding side column headers (which may be 1...to n), some sort of structure holding main columns headers (which would be as big as the time period), and then structures holding the actual rows. The generic part was the ability to pass some random object and define which I would then define the columns I required for etc. –  GraemeMiller Dec 12 '11 at 14:25
    
Ever thought about using the "dynamic" keyword for this task? –  Dimi Toulakis Apr 11 '12 at 11:14
1  
This interesting discussion about designing around data might give you direction/inspiration. –  TheSilverBullet Sep 13 '12 at 11:41
add comment

1 Answer 1

If you don't need to do any actual operations on the field data (height, weight, etc.) you could use reflection as outlined in this answer on Stack Overflow to get the property values and names to display from the object.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.