c# - BindingFlags.OptionalParameterBinding varying behaviour in different frameworks. Bug in .NET? -
i've tried force activator.createinstance
use constructor default parameters.
i've found suggestion, repeated few times on (first comment) http://connect.microsoft.com/visualstudio/feedback/details/521722/system-activator-createinstance-throws-system-missingmethodexception-with-constructor-containing-an-optional-parameter
i wanted run on mono , didn't work, throwing missingmethodexception
. before filing bug i've made experiment on .net 4.5:
class program { static void main(string[] args) { new a(); activator.createinstance(typeof(a), bindingflags.createinstance | bindingflags.public | bindingflags.instance | bindingflags.optionalparambinding, null, new object[] {type.missing}, null); } } class { public a() { console.writeline("first"); } public a(int = 5) { console.writeline("second"); } }
of course, result predictable:
first second
then i've tried remove type.missing
parameter see happens, hoping find way invoke constructor varying number of default parameters.
i flabbergasted see nothing changed! passing new object[]{}
i've expected:
first first
wondering type.missing do, and, golly!, why mentioned in examples on internet, i've changed framework.
on .net 4.0 same, on .net 3.5 result was
first first
this seems odd. there documented reasons of such behaviour?
what proper way call constructor possibly many optional parameters?
Comments
Post a Comment