I am trying to develop a framework for several applications that we are developing here, and one of the infrastructure classes that I am trying to create is creating a database. Ideally, I would have a method in which I could pass the following two methods to it: CreateDatabaseTables () and ResetDatabaseValues ();
For example, I can have three applications, which I will call Application1, Application2, and Application3; each of these applications will have a different database schema that I would include in the code (for example, in CreateDatabaseTables there are a bunch of Create Table commands). I want to create a single database method that can be used by each of them, so that it looks something like this:
Application1
BuildLocalDatabase(CreateTablesForApp1(),ResetDatabaseValuesforApp1())
Application2
BuildLocalDatabase(CreateTablesForApp2(),ResetDatabaseValuesforApp2())
Application3
BuildLocalDatabase(CreateTablesForApp3(),ResetDatabaseValuesforApp3())
The BuildLocalDatabase method will do something like:
publid bool BuildLocalDatabase(CreateTablesForApp(),ResetDatabaseValuesforApp()) { - see if database file exists; if it does, delete it - create a new database file - call CreateTablesForApp - if the tables were created successfully, call ResetDatabaseValuesForApp }
Any thoughts on how I could do this. There is actually a bunch of validation and other things that I would like to do in the BuildLocalDatabase function, and obviously my goal here is to minimize the amount of duplication code in each application ... any suggestions on how you can to do it. I think in C ++ I could just pass the CreateTablesForApp and ResetDatabaseValuesForApp methods as function points, but there seems to be no way to do this in C #. And delegates seem to be doing this well, since I'm really limited to just one method (and multicast seems to want to run the methods twice).
c #
user405965
source share