Hi, all,
Hopefully this will make sense:
I have 2 classes that implement the same generic interface.
public interface IAgingReport<T>
{
T GetAgingReport(DateTime dAsOfDate);
}
1 of the two classes that implements the interface, returns a dataset:
public class bzAgingReport : IAgingReport<Dataset>
{
public Dataset GetAgingReport(DateTime dAsOfDate);
{
// get data for aging report, return dataset
}
}
The 2nd class also implements the interface, but returns an XML
string:
public class wAgingReport : WebService, IAgingReport<string>
{
[WebMethod]
public string GetAgingReport(DateTime dAsOfDate)
{
// return XML string
}
The reason I'm using one interface is because the client piece might
be using web services, or it might be using remoting. I want to use
an interface-based approach on the client-side, and use a common code
base, regardless of which communication approach is being used.
On the client side, I can create a regular .NET object (which is
either a web reference object or a remoting object), but I can't
figure out how to write "generic" code to deal with the different data
types that might be coming back (XML string or dataset).
So in my client piece, I have (and this is pseudocode)
object oReturnObject = either web service object or remoting
proxy object
if (using web services)
{
IAgingReport<stringoAgingReport;
oAgingReport = (IAgingReport<string>)oReturnObject;
string cXMLResults =oAgingReport.GetAgingReport(dAsOfDate);
MyDataSet.ReadXml(new StringReader(cXMLResults));
}
else
{
IAgingReport<DataSetoAgingReport;
oAgingReport = (IAgingReport<DataSet>)oReturnObject;
MyDataSet = oAgingReport.GetAgingReport(dAsOfDate);
}
// at this point, either way, I have my results in a dataset
Essentially, in the first example, I'm utilizing the interface
function that returns a string (and then convert to a dataset). In
the second example, I'm using the interface function that returns a
dataset.
here's my question - this all "works", but I've been trying to figure
out how to avoid the 'IF' block above. I'm wondering if I need a 2nd
usage of generics, but I can't figure out which one. I've tried
different combinations of specifying a variable type, but nothing I
try seems to work.
Thanks in advance,
Kevin