Skip to content

Instantly share code, notes, and snippets.

@ValdemarOrn
Created October 10, 2011 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ValdemarOrn/1274421 to your computer and use it in GitHub Desktop.
Save ValdemarOrn/1274421 to your computer and use it in GitHub Desktop.
Create a list of an Anonymous Type
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>();
}
}
@ValdemarOrn
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment