Call GetConstructor to get the constructor : ConstructorInfo « Reflection « C# / C Sharp






Call GetConstructor to get the constructor

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

class MainClass
{
    public static StringBuilder CreateStringBuilder()
    {
        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);

        return sb;
    }
}

   
    
    
  








Related examples in the same category

1.Invoke in Constructor through ConstructorInfo
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