Last active
December 23, 2015 13:39
-
-
Save DForshner/6643722 to your computer and use it in GitHub Desktop.
Create a new instance of class by name (string) using a look up table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates new instance of a class by name (string). | |
public IClass GetDataSource(string className) | |
{ | |
// Should handle case where the className does not exist in dictionary. | |
// Lookup table that maps class string names to a constructor action. | |
var classDictonary = new Dictionary<string, Func<IClass>> | |
{ | |
{ "ClassA", () => new ClassA()}, | |
{ "ClassB", () => new ClassB()}, | |
{ "ClassC", () => new Class()}, | |
}; | |
// Create new instance | |
return classDictonary[reportName].Invoke(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment