Accessing the constructor by using Reflection

Posted by Md. Rashim Uddin on Stack Overflow See other posts from Stack Overflow or by Md. Rashim Uddin
Published on 2010-05-21T09:09:04Z Indexed on 2010/05/21 9:20 UTC
Read the original article Hit count: 438

Filed under:
|
|

Assume the class is public and and the constructor is internal like as

Public class A
{
    private string text;

    internal A(string submittedText);

    public string StrText { get; }
}

In this case how could I Access the constructor by using Reflection. What I have done so far

Type[] pTypes = new Type[1];

pTypes[0] = typeof(object);

object[] argList = new object[1];

argList[0] = "Some Text";


ConstructorInfo c = typeof(A).GetConstructor
                (BindingFlags.NonPublic |
                 BindingFlags.Instance,
                 null,
                 pTypes,
                 null);


A foo = (A)c.Invoke(BindingFlags.NonPublic,
                    null,
                    argList,
                    Application.CurrentCulture);

But it shows an error. Any Suggestions

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection