Invoke in Constructor through ConstructorInfo : ConstructorInfo « Reflection « C# / C Sharp

Invoke in Constructor through ConstructorInfo


using System;
using System.Text;
using System.Reflection;

class MainClass {
    public static void Main() {
        Type type = typeof(StringBuilder);

        Type[] argTypes = new Type[] { typeof(System.String), typeof(System.Int32) };

        ConstructorInfo cInfo = type.GetConstructor(argTypes);

        object[] argVals = new object[] { "Some string", 30 };
        StringBuilder sb = (StringBuilder)cInfo.Invoke(argVals);

Related examples in the same category

1.Call GetConstructor to get the constructor
2.Get parameter information by using ConstructorInfo and ParameterInfo
3.ConstructorInfo Class Discovers the attributes of a class constructor
4.Searches for a constructor whose parameters match the specified argument types and modifiers
5.Searches for a constructor using the specified binding constraints.
6.Get the constructor that takes an integer as a parameter.
7.Returns all the public constructors defined for the current Type.
8.Get Property/Constructor Info