Creating Type Instances by Using ConstructorInfo

Once you have a System.Type object instance, you can use it to create an instance of the type it represents. This can be done by querying for a ConstructorInfo object. The ConstructorInfo class is used to discover the attributes of a constructor, and it provides access to constructor metadata. Most importantly, a ConstructorInfo instance can be used to invoke a type's constructor.

Before we start invoking constructors, let's discuss how you can get a hold of one of these powerful objects. The Type class provides two methods for retrieving ConstructorInfos: GetConstructors and GetConstructor.

Using the GetConstructors Method

The GetConstructors method comes in two flavors. The easiest flavor to ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.