I'm using Type.GetConstructor(Type.EmptyTypes)
to get the default constructor for a class. It works if the class has a default constructor with no parameters (class A
). But it doesn't work if a class has a constructor with all parameters optional (class B
). Program doesn't know what the optional parameters are because it only needs the default constructor. What can statements can I use to make it work for both cases? Thanks, appreciate any help!
public class A
{
public A() {}
}
public class B
{
public B(int i = 0, string str = "") {}
}