I'm building the app which will work with SQLite and what I want to do now is to get table creation strings for each entity which should be stored with code like this:
table_creation_string1 = Book.GetTableCreationString();
table_creation_string2 = Scroll.GetTableCreationString();
Which will allow me to do the minimal work with new entities creation using custom attributes to store table name and fields names.
Here is my setup example:
[System.AttributeUsage(System.AttributeTargets.Class)]
public class DBItemAttribute : System.Attribute
{
public string TableName;
public DBItemAttribute(string table_name)
{
TableName = table_name;
}
}
internal abstract class DBItem
{
...
}
[DBItemAttribute("book_table")]
internal class Book : DBItem
{
...
}
[DBItemAttribute("scroll_table")]
internal class Scroll : DBItem
{
...
}
The problem I faced is that I can't get an attribute value for Book and Scroll classes without constructing the object. In other terms - using smth like that:
string table1 = Scroll.GetTableName();
string table2 = Book.GetTableName();
with next values output
"scroll_table"
"book_table"
So I'm looking for the best solutions for that or some good alternatives.
I've already learned that static method in base class will not work for that due it seems to be not possible to get derived class info calling static method defined in base.
UPD: The code like
table_creation_string1 = new Book().GetTableCreationString();
works for a sure, but I wonder if it can be done in way I've described above.