I am trying to use reflection to create instance of a class. But it is sealed internal and has private constructor. I wonder how can i initiaise it and as its part of framework, I can only use reflection to take it out?
internal sealed class ABC
{
private ABC(string password){}
public static ABC Create(string password){};
}
Added:
System.ServiceModel.Channels.SelfSignedCertificate is the internal class I am trying to use
First of all, the very fact that it is internal means you’re not supposed to be doing what you want to do.
You should seriously try to find an alternate route to what you want to accomplish.
Unfortunately, you don’t tell us what you want to accomplish, only the next step you think you want to do, so that’s what I can help you with.
This code will work, and accesses the public static method:
Note that this relies on having access to another type in the same assembly, that is public. If you don’t have that, you need to get hold of the Assembly object that contains the type.