Is there a way to take a class name and convert it to a string in C#?
As part of the Entity Framework, the .Include method takes in a dot-delimited list of strings to join on when performing a query. I have the class model of what I want to join, and for reasons of refactoring and future code maintenance, I want to be able to have compile-time safety when referencing this class.
Thus, is there a way that I could do this:
class Foo
{
}
tblBar.Include ( Foo.GetType().ToString() );
I don't think I can do GetType() without an instance. Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…