System.Type extension methods

CreateInstance(params object[] args)

Summary: Returns a new instance of the specified Type.
C# Example:
var t = typeof(Person);
object p = t.CreateInstance();

object p2 = typeof(Person).CreateInstance("FirstName", "LastName");

CreateInstance<T>(params object[] args)

Summary: Returns a new instance of the specified Type cast as the specified Generic type, passing in the specified constructor arguments.
C# Example:
var t = typeof(Person);
Person p = t.CreateInstance<Person>();

Person p2 = typeof(Person).CreateInstance<Person>("FirstName", "LastName");

Last edited May 4, 2012 at 2:12 PM by crpietschmann, version 3

Comments

No comments yet.