From the course: CLR Reflection for Developers
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Constructing objects - Windows Tutorial
From the course: CLR Reflection for Developers
Constructing objects
- [Instructor] So one of the things that we can use the reflective API to do is we can actually, for example, once we have hold of a constructor info object, we can actually use that and invoke it in order to construct a particular object. The means for doing so is actually very straightforward. Once we have the constructor info instance and again, when we get a hold of the constructor, the parameter list will be important to know which constructor we're about to invoke, but also because we're going to need to make sure on our end that the parameters that we use line up against the constructor info object and the constructor that it represents. Once we know that, though, we can simply call the invoke method, which is part of the constructor info object, and pass it an object array that lines up one to one with the parameter list. Assuming that works, the result of that call will in fact be a constructed object reference. Let me show you what we mean here.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.