I have an interface IDatabase that interfaces a few different ways to access a database. For example using RESTful, or MySqlDirectConnect.
Next I have a class foo that has member variables A, B, C that need to pull there data out of the database.
public class foo
{
private string a;
private int b;
private int c;
}
Originally, I was going to create a Get method for every single member variable. Using Generics, you specify what interface you want to use.
public string GetA<T>() where T: IDatabase
{
//example might be GetA<RESTful>();
}
public int GetB<T>() where T: IDatabase
{
//example might be GetB<MySQL>();
}
and so on....
problem I see is that if the database changes I have to go back and change all these methods. In some cases class foo might have around 20 variables with a Get() method for each.
So I would like to create a really generic GetValue() where I can specify both the interface and the variable i would like to query for.
something along the lines of:
public object GetValue<T>(the class variable I want to query) where T: IDatabase
{
//query database using type T and return it to the variable specified
}
I would like to avoid having a conditional for every member variable inside the method.
So is this possible?