I'm designing a reporting engine for my project. The project will have several reports, each of which can be expressed as a Linq query; some will have parameters, while others won't.
Now in order to meet my clients' requirements, I need to return the results of the queries in XML format, so that they can apply an XSL transform to make it look pretty according to their own taste.
So, my plan thus far is to have an abstract Report
base class, from which all my reports will be derived. The base class will need the following methods:
public virtual void SetParameter(string ParameterName, object Value) {
throw new NotImplementedException("This report does not accept parameters.");
}
public abstract object GetData(); // what return type?
public XElement GetXMLData() {
// calls GetData() and uses some kind of reflection to turn the data into XML?
}
To flesh this out a little more: SetParameter()
is fairly self-explanatory. GetData()
is supposed to contain the Linq query, and return an IEnumerable<'a>
type, where 'a
is the anonymous type of the final result. But obviously you can't declare something as being of anonymous type, so I need some other generic way of relating to the results of my Linq query - one that will allow me to iterate through the returned fields and create an appropriate XML schema.
What should the return type of GetData()
be? How do I get the field names/values? Alternatively, is there a better way to achieve my objective?