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 = "") {}
}
Say I have the following class:
Basically, you’re asking for a query that will find the constructors that match constructor 1 and 3 above? If so, use this:
Incredibly nasty query, but it gets the job done returning only 1 and 3 above.