C#: Dynamically instantiate different classes in the same statement?
        Posted  
        
            by C. Griffin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by C. Griffin
        
        
        
        Published on 2010-04-08T21:08:42Z
        Indexed on 
            2010/04/08
            21:13 UTC
        
        
        Read the original article
        Hit count: 590
        
Here is a simplified version of what I'm trying to do:
Without having multiple if..else clauses and switch blocks, can I mimic the behavior of Javascript's eval() shudder to instantiate a class in C#?
// Determine report orientation -- Portrait or Landscape
// There are 2 differently styled reports (beyond paper orientation)
string reportType = "Portrait";
GenericReport report;
report = new eval(reportType + "Report()");  // Resolves to PortraitReport()
The need stems from the fact that I have 6 types of Crystal Reports (that do the same thing, but look drastically different) for 50 states. There are 3 styles each, rather than entertain the notion of a giant switch block with nested if..else statements determining which of 900 reports to use, I was hoping for an eval-like solution.
© Stack Overflow or respective owner