Created
October 10, 2011 00:47
-
-
Save ValdemarOrn/1274421 to your computer and use it in GitHub Desktop.
Create a list of an Anonymous Type
This file contains 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
class AnonList | |
{ | |
/// <summary> | |
/// Creates a list of type T using a prototype object. Prototype can be any object, including an anonymous type. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="prototype">The prototype object, of which a List of the same type is returned</param> | |
/// <returns>A new empty List of the same type as prototype</returns> | |
public static List<T> CreateAnonList<T>(T prototype) | |
{ | |
return new List<T>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: I wouldn't recommend tricks like these for real code. If you need to result to this trick, you may want to rethink your data types :)