Can't Use an Interface
The methods that deal with the database are Read, Write, Exists & Delete. Read, Exists & Delete are static methods. Write is an instance method. Because of the static methods, I can not use an interface.
Generic Method & Reflection
Is there a way that I can use a typed method and reflection to interact with the database? Using this idea of attributes on the class and passing the type as a parameter to one of these database interaction methods, can reflection be used to identify each of the fields for reading, writing, existence and deletion?
An Example
I'd like to outline a few examples.
Suppose I have a class Foobar.
I might be able to read a Foobar record using code that looks like this:
Foobar foobar = Database.Read<Foobar>(foobarId);
I might be able to see if Foobar record exists using code like this:
if ( Database.Exists<Foobar>(foobarId) ) { ... }
I might be able to write a Foobar record list this:
Database.Write<Foobar>(foobar);
Or, this (as the type can be determined from the parameter):
Database.Write(foobar);
And I could delete like this:
Database.Delete<Foobar>(foobarId);
Questions
Would this give me compile-time information for the foobarId parameter? If a key for a particular table was comprised of multiple values, would a params parameter be adequate? Or, would a multiple-type generic be better (e.g., Database.Delete<T, P1, P2>(P1 a1, P2 a2))?
Script Generation
Even with the generic type doing all the work, the database creation and conversion scripts would still need be be generated from the type ... but the compiled type could be used to generate this information rather than some other file format.
Database Identifier
I would still need to pass in a database identifier as well.