i have different scenario. need create instance of class public having constructors internal. class has no default constructor.
i tried below ways, didn't work.
activator.createinstance(typeof(classname)); activator.createinstance(typeof(classname), nonpublic:true); activator.createinstance(typeof(classname),true); activator.createinstance(typeof(classname), new object[]{double,bool}); i tried this, ended system.missingmethodexception.
var constructors = typeof(classname).getconstructors(); foreach(var ctor in constructors) ctor.invoke(new object[] {double, bool}); i am not able use bindingflags in xamrarin. stuck, have solution this?
i found solution myself. here did.
constructorinfo info = typeof(classname).gettypeinfo().declaredconstructors.first(); classname e = info.invoke(new object[] { parameters }) classname; i hope might someone. cheers:)
Comments
Post a Comment